我想要实现的是向上移动并覆盖 UINavBar 的 UISearchBar,并在其右侧包含一个取消按钮。一切顺利,直到我使用以下代码行:
searchDC = [[[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self] autorelease];
最终发生的是 UITableView 不会滚动,但其他一切都按预期运行。如果我删除该行,我的导航栏是可见的,搜索栏就位于它的下方,也没有取消按钮。
有什么想法吗?
绘制搜索栏的代码是:
self.navigationItem.title = @"Search";
searchBar = [[[UISearchBar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.view.bounds.size.width, 44.0f)] autorelease];
searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
searchBar.autocapitalizationType = UITextAutocapitalizationTypeNone;
searchBar.keyboardType = UIKeyboardTypeAlphabet;
searchBar.delegate = self;
[searchBar becomeFirstResponder];
tableView.tableHeaderView = searchBar;
tableView.tableHeaderView.frame = CGRectMake(0.f, 0.f, 480.f, 44.f);
searchDC = [[[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self] autorelease];
searchDC.searchResultsDataSource = self;
searchDC.searchResultsDelegate = self;
searchDC.searchResultsTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
searchDC.searchResultsTableView.scrollEnabled = YES;
overlayView.frame = CGRectMake(0, 50, 320, 480);
[self.view addSubview:overlayView];
[self.view bringSubviewToFront:overlayView];
最佳答案
没有足够的信息来回答这个问题。您需要在设置 UISearchDisplayController 的位置显示 UIViewController 或 UINavigation Controller 代码(.h 和 .m)。
编辑:
您完全错误地实现了这一点。 Apple 有一个很好的例子来说明如何实现这个 http://developer.apple.com/iphone/library/samplecode/TableSearch/Introduction/Intro.html
关于ios - UITableView 不使用 UISearchBar 滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3146813/