我是IOS的新手,似乎無法得到這個工作,我有一個輸入在我的應用程序,從中我想要隱藏鍵盤,每當用戶按下返回或關聯按鈕(searchGo)resignfirstresponder崩潰我的ios應用程序
以下是我的代碼:
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
適當的.m片斷
-(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];
}
對不起,如果這是一個愚蠢的問題,但我做錯了什麼。
是否將Interface Builder(IB)中的屬性連接到GUI元素,或者是否有編程視圖?然後,你可以檢查你的發送者是否是一種UIResponder(如果([sender isKindOf:[UIResponder class]])...),並且允許它退出第一個響應者(if([(UIResponder *))發件人canResignFirstResponder]))...) – GeT 2012-02-27 18:27:22
@GeT編程主要是 – 2012-02-27 18:30:06