ios – UITableView不使用UISearchBar滚动

前端之家收集整理的这篇文章主要介绍了ios – UITableView不使用UISearchBar滚动前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想要实现的是一个UISearchBar向上移动并覆盖UINavBar,并在其右侧包含一个取消按钮.一切顺利,直到我使用以下代码行:

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相关文章