ios - UITableView 不使用 UISearchBar 滚动

标签 ios objective-c uitableview cocoa-touch uisearchbar

我想要实现的是向上移动并覆盖 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/

相关文章:

ios - Storyboard的 View 与模拟器的 View 不同

iphone - CoreData 中的关系和实体

iphone - 难以解析包含 '\u00' 等字符的响应

ios - 编码的自动布局对于 UITableView 无法正常工作

ios - UIAutomation 和 XCTestCase : how to wait for a button to activate

ios - React-Native AsyncStorage.clear() 在 IOS 上失败

ios - Whatsapp 消息布局 - 时间和消息在同一行

ios - 将 JSON 字符串从一个 View 传递到另一个 View

objective-c - 从分组的 UITableView 中删除部分后出现间隙

ios - 如何将 stackViews 添加到 UITableViewCell?