【发布时间】:2010-06-30 06:02:47
【问题描述】:
我想要实现的是一个向上移动并覆盖 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];
【问题讨论】:
标签: ios objective-c uitableview cocoa-touch uisearchbar