我有一个UIViewController
,它是一个UISearchBarDelegate
和MKMapViewDelegate
。在iOS 4.2中测试时,searchBarSearchButtonClicked
事件可以正常工作,但是当点击取消按钮时,searchBarCancelButtonClicked
从未被调用。在4.3中一切正常。我有其他视图具有相同的代码,并且它们可以正常工作。我已经三重检查了方法签名。
这可能与地图视图有关,还是我做错了什么?
我的.h文件:
@interface MyViewController : UIViewController <UISearchBarDelegate,MKMapViewDelegate,UIAlertViewDelegate>{
MKMapView *mapMainView;
UISearchBar *sBar;
}
@property (nonatomic, retain) UISearchBar *sBar;
@end
我这样创建搜索栏:
sBar = [[[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320.0, 70.0)] autorelease];
sBar.delegate = self;
sBar.showsCancelButton = YES;
[self.view addSubview:sBar];
[sBar becomeFirstResponder];
方法:
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
{
[searchBar resignFirstResponder];
searchBar.hidden = YES;
}
有人知道为什么会发生这种情况吗?