我想要实现的是一个UISearchBar,向上移动并覆盖UINavBar,并在其右侧包含一个取消按钮。一切顺利,直到我用下面的代码行:UITableView不滚动使用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];
我的歉意,我修复了原帖 – 2010-07-03 05:56:40