I want the keyboad show automatically onload, but it did not work as i expect
here is the code i use:
- (void)viewDidLoad {
[super viewDidLoad];
[seachBar2 setDelegate:self];
}
- (BOOL)Searchbar2ShouldReturn:(UISearchBar *)searchBar2 {
[searchBar2 becomeFirstResponder];
return YES;
}
Coud somebody will point me how to fix this
thank you somuch
- (void)viewDidLoad {
[super viewDidLoad];
[seachBar2 setDelegate:self];
[seachBar2 becomeFirstResponder];
}
Just came across this, and it helped but the answers are vague.
All you need to do now in iOS 5 is make an outlet connection to your object (for example a UITextField) and then in viewDidLoad method type;
[myTextField becomeFirstResponder];
or for your search bar
[searchBar2 becomeFirstResponder];
Make sure searchBar2 in your code points (IBOutlet) to the searchBar in the Interaface Builder.
in your code:
IBOutlet UISearchBar *searchBar2;
In IB:
goto the search bar's Connections Inspector (apple-2) and drag the Referencing Outlet to File Owner and select searchBar2
Hope this helps.
You do need to override viewDidAppear:, and verify it's actually being called (put a breakpoint or an NSLog() statement in there). You should also determine the language you're coding in (it's Objective C).
Your -Searchbar2ShouldReturn: method will never be called by the system. I think you may need to go back and work through a few of Apple's tutorials here; your grasp of the frameworks seems tenuous, at best.
Related
I'm doing an application which consists of asking a question after a certain time, and the user can't do anything more, unless he answers the question, I've managed to mantain the window always on top by setting a 9999 level:
[_idleWindow setLevel:9999];
I would like to know if there is a way to avoid changing virtual desktop when the window is open, or to focus the window again when you change the virtual desktop.
Look at setCollectionBehavior:
[_idleWindow setCollectionBehavior:NSWindowCollectionBehaviorMoveToActiveSpace|NSWindowCollectionBehaviorTransient|NSWindowCollectionBehaviorFullScreenDisallowsTiling|NSWindowCollectionBehaviorFullScreenAuxiliary];
might do the trick.
Also, if you can use NSPanel instead of NSWindow, you can add the style mask: NSWindowStyleMaskNonactivatingPanel to give your window key status even when your app isn't active. (you'll need to implement canBecomeKeyWindow in the NSPanel subclass)
After a few researches on Google, I have found the solution on another Stackoverflow post.
Solution:
You need to add this code either in your xib / storyboard, either in your NSWindowController subclass -windowDidLoad method, either in your designated initialiser of your NSWindow subclass :
- (void) awakeFromNib {
[self setCollectionBehavior:NSWindowCollectionBehaviorCanJoinAllSpaces]; //this was the one that worked for me
}
OR
- (id)initWithContentRect:(NSRect)contentRect
styleMask:(NSUInteger)styleMask
backing:(NSBackingStoreType)bufferingType
defer:(BOOL)flag {
if (self = [super initWithContentRect:contentRect styleMask:styleMask backing:bufferingType defer:flag]) {
[self setCollectionBehavior:NSWindowCollectionBehaviorCanJoinAllSpaces];
}
return self;
}
OR if you have a NSWindowController
- (void)windowDidLoad {
[super windowDidLoad];
[[self window] setCollectionBehavior:NSWindowCollectionBehaviorCanJoinAllSpaces];
}
OR Edit the nib file and add this behaviour to your window in XCode.
Credits: Stefan Szekeres
I have a window that I am creating based off of clicking a row in a Tableview, instantiated like such:
HKLUserProfileController *userProfileController = [[HKLUserProfileController alloc] initWithNibName:#"HKLUserProfileController" bundle:nil];
_wc =[[NSWindowController alloc] initWithWindowNibName:#"HKLProfileWindowController"];
[_wc.window.contentView addSubview:userProfileController.view];
// other extraneous stuff here
[_wc showWindow:self];
if([_wc.window canBecomeKeyWindow]) {
[_wc.window makeMainWindow];
[NSApp activateIgnoringOtherApps:YES];
[self makeKeyAndOrderFront:self];
}
This works, but I cannot seem to get the window to become the main/key/front window. I've tried:
... from this place where I am creating the WindowController, and also from inside viewDidLoad/loadView of the NSViewController whose View was added to the Window. No dice. (this is my ultimate goal here, so if you see something obvious i'm missing, please point it out).
So I realized that I should be trying to do this in the subclass of the WindowController itself... so I thought to put it in windowDidLoad, but no result. I set some breakpoints, and tried the other logical init methods, and to my surprise, NONE of them fire at all.
#implementation HKLProfileWindowController
- (void)windowDidLoad {
[super windowDidLoad];
// breakpoint here
}
-(void)awakeFromNib {
// breakpoint here
}
- (id)init {
// breakpoint here
self = [super init];
if (self) {
// breakpoint here
}
return self;
}
#end
My xib is connected as an Outlet / Delegate to my File's Owner properly, as far as I can tell. This is leading me to believe this is the root of the problem, but for the life of me, I can't figure out what is the issue...
Thanks...
EDIT
I realize what is happening with the keyWindow - because it's coming from shouldSelectRow in the TableView, it IS becoming key on mouseDown events, but the first window - which holds the TableView - is becoming key again on mouseUp events... which is maddening!
Will search for solutions to that, but open to comments here!
(still can't figure out why the init methods are not firing though...
You use NSWindowController in your alloc/init line and you expect it to become an HKLProfileWindowController instance? Why?
You also need the File's Owner custom class set to HKLProfileWindowController but there's no reason to expect that's sufficient to get an HKLProfileWindowController instance when you ask for an NSWindowController. What you get is an NSWindowController and none of the subclass code is used.
I'll delete this answer if your code is from before you implemented the HKLProfileWindowController class, but given what you have pasted here, that's why your breakpoints don't get hit.
Is it possible to redraw the whole view.
I need it to complete my language settings. The problem is that the language only changes after the views there drawn again. Like you go out of settings and then go in again, then the language is changed. But the moment you save everything, the language stays the same.
So how should i redraw my views, or by best the whole app, after the language change was found?
In ARC:
- (void)setLanguage:(LanguageType)languageType
{
_language = languageType;
//TODO:your settings
[_theWholeView setNeedsDisplay];
}
If that can not work , there is a very troublesome solution , it can reload the whole view.
You can code like this:
In the view.h , you need creat a delegate.
#protocol WholeViewDelegate
- (void)reloadData;
#end
In the view.m
- (void)setLanguage:(LanguageType)languageType
{
_language = languageType;
//TODO:your settings
[_delegate reloadData];
}
In the controller you need to implement the delegate
In the controller.m
- (void)reloadData
{
if(_wholeView)
{
[_wholeView removeFromSuperview];
}
// in the wholeView init method you should refresh your data
_wholeView = [[WholeView alloc] init];
self.view addSubview:_wholeView
}
Yes. Call [UIView setNeedsDisplay] (reference).
Just call setNeedsDisplay.. It will resolve the problem. setNeedsDisplay actually calls the drawRect function in the UIView class by passing the frame of the view as the rectangular parameter. Hope that helps....
When adding a textfield, the keyboard opens correctly, however I cannot get the done button to work properly. I know thee are other similar posts, however for whatever reason they do not seem to work for me.
When I say "not work" i mean the keyboard does not close.
Any suggestions would be appreciated.
Add this and let me know:
- (BOOL)textFieldShouldReturn:(UITextField*)aTextField
{
[aTextField resignFirstResponder];
return YES;
}
Remember to add the viewController as delegate of your text field
I believe this is what you're looking for. Its a UITextFieldDelegate callback thats called anytime the Done/Return button is used on the keyboard.
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
You'll need the delegate in your interface
#interface Class : UIViewController <UITextFieldDelegate>
If you're textfield is in a ModalViewController using the FormSheet style you need this as well.
- (BOOL)disablesAutomaticKeyboardDismissal
{
return NO;
}
I would like to create a table like the iPhone (calls) which are displayed three labels.
UITableViewCellStyleSubTitle displays only two options as well as UITableViewCellStyleSubValue1.
Do I have to manually create it?
Thanks.
/ / English Google
A third place to put something is the accessoryView, which shows up to the right of the cell.
The best way to have full control over a cell is to make a custom UITableViewCell. An example.
Yes, you have to manually create it. Watch this YouTube video for a tutorial.
Also, next time you ask a question, provide a more descriptive title, and you will likely get more views and answers.
As Peter DeWeese was saying you have to make a custom UITableViewCell.
Let me point out that since iOS 6 this is the only correct way to do it.
Make a subclass UITableViewCell.
In the initializer (.m file) you can rewrite the style that is given when the super class is called.
code example:
(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:--------UITableViewCellStyleSubtitle------- reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
Go to your TableViewController and registrate that cell in the viewDidLoad method.
[self.tableView registerClass:[---------FriendCell---------- class] forCellReuseIdentifier:#"vriendCel"];
//And if someone would help me out to put my code properly, can't seem to fix it. :)