【发布时间】:2010-06-13 03:15:36
【问题描述】:
我有一个指定为 UISearchBarDelegate 的 UITableViewController。到目前为止,我已经以编程方式将 UISearchBar 添加到表格的 headerView 中,没有任何问题。
我开始用完屏幕空间,所以我决定取消我正常的 UINavigationController 标题(即文本),并添加以下代码,将我的 SearchBar 从表格移动到 UINavigationBar:
// (Called in viewDidLoad)
// Programmatically make UISearchBar
UISearchBar *tmpSearchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0,0,320,45)];
tmpSearchBar.delegate = self;
tmpSearchBar.showsCancelButton = YES;
tmpSearchBar.autocorrectionType = UITextAutocorrectionTypeNo;
tmpSearchBar.autocapitalizationType = UITextAutocapitalizationTypeNone;
[self set_searchBar:tmpSearchBar];
[tmpSearchBar release];
self.navigationItem.titleView = [self _searchBar];
此代码按预期工作 - 我的 UINavigationBar 现在是 UISearchBar。 但是,我的委托方法:
/** Only show the cancel button when the keyboard is displayed */
- (void) searchBarDidBeginEditing:(UISearchBar*) lclSearchBar
{
lclSearchBar.showsCancelButton = YES;
}
...不再被调用。我已经断点,并且我已经确认 UISearchBar 的委托确实是自我,即视图控制器。奇怪的是,这个委托方法仍然可以正常调用:
/** Run the search and resign the keyboard */
- (void) searchBarSearchButtonClicked:(UISearchBar *)lclSearchBar
{
_deepSearchRan = NO;
[self runSearchForString:[[self _searchBar] text] isSlowSearch:NO];
[lclSearchBar resignFirstResponder];
}
知道为什么 UINavigationBar 会吞下我的委托调用吗?我错过了什么?
【问题讨论】:
标签: iphone uinavigationbar uisearchbar