I am new to IOS and can’t seem to get this to work , I have an input filed on my app,from which I want to hide the keyboard whenever the user either presses return or the associated button (searchGo)
The following is my code :
mainViewController.h
@interface kepnMainViewController : UIViewController <kepnFlipsideViewControllerDelegate, MKMapViewDelegate>
{
MKMapView *_mapView;
IBOutlet UITextField *searchBox;
IBOutlet UIBarButtonItem *searchGo;
IBOutlet UIBarButtonItem *searchNearby;
MKAnnotationView *annotationView;
}
@property (strong, nonatomic) MKMapView *_mapView;
@property (strong, nonatomic) MapAnnotation *annotation;
@property (strong, nonatomic) UIPopoverController *flipsidePopoverController;
@property (strong, nonatomic) MKAnnotationView *annotationView;
@property (strong, nonatomic) UIBarButtonItem *searchGo;
- (IBAction)showInfo:(id)sender;
- (IBAction)searchGo:(id)sender;
- (IBAction)showNearby:(id)sender;
- (IBAction)searchBoxReturn:(id)sender;
- (void) setPlaceMarker: (CLLocationCoordinate2D) coord :(NSString*) title :(NSString*) subtitle;
@end
Appropriate .m snippet
-(IBAction)searchGo:(id)sender
{
NSLog(@"sender object %@",sender);
[sender resignFirstResponder];
NSLog(@"search button pressed and textbox = %@",searchBox.text);
}
-(IBAction)searchBoxReturn:(id)sender
{
NSLog(@"search box return ");
[sender resignFirstResponder];
}
Sorry if this is a dumb question but what am I doing wrong.??
UIBarButtonItemisnt anUIViewand therefore definitely not anUIResponder. Instead, it’s a subclass ofNSObject, which doesn’t respond to- (void)resignFirstResponder.(solution: remove the
[sender resignFirstResponder];lines)