Keyboard not show onload
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;
}
开发者_StackOverflowCoud 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.
精彩评论