I’m using an UISearchBar in my app. When I run on simulator everything is fine. On device does not work. On device, my searchbar frame is changing but keybord doesn’t show. NSlogs are working. My code is here:
-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
NSLog(@"wrote");
}
-(BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar {
[self.mySearchBar setFrame:CGRectMake(0,100,mySearchBar.frame.size.width,mySearchBar.frame.size.height)];
mySearchBar.showsCancelButton=TRUE;
mySearchBar.text=@"nowwrite";
NSLog(@"chosed");
}
-(void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
NSLog(@"cancel");
}
- (void)viewDidLoad
{
mySearchBar.delegate=self;
[super viewDidLoad];
}
and my .h file
@interface sehirRehberi : UIViewController <UISearchBarDelegate,MKMapViewDelegate,CLLocationManagerDelegate,UINavigationControllerDelegate> {
IBOutlet UISearchBar *mySearchBar;
}
@property(retain, nonatomic) UISearchBar *mySearchBar;
Have you made the view first responder? That’s necessary for the keyboard to show. I’m not sure why it’s working on the simulator, but you should call
[self becomeFirstResponder];in yourviewDidLoadmethod to enable the view to receive keyboard events and thus show the keyboard. When you’re done (viewWillDisappear, etc.), just call[self resignFirstResponder];. I think that’s your problem. It’s hard to tell without more explanation/code.