我有一个UITableViewController
,我想要一个UISearchBar
在顶部,所以我使用
viewForHeaderInSection:
委托方法,因为当我滚动时我不想隐藏UISearchBar
. 问题是(仅 iOS7)当我按下取消按钮时UISearchBar
消失。
这是一些代码:
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:UITableViewStylePlain];
if (self) {
// Custom initialization
self.filteredListContent = [[NSMutableArray alloc] init];
mySearchBar = [[UISearchBar alloc] init];
mySearchBar.delegate = self;
[mySearchBar setAutocapitalizationType:UITextAutocapitalizationTypeNone];
[mySearchBar sizeToFit];
searchDisplayController = [[UISearchDisplayController alloc]initWithSearchBar:mySearchBar contentsController:self];
[searchDisplayController setDelegate:self];
[self setSearchDisplayController:searchDisplayController];
[searchDisplayController setSearchResultsDataSource:self];
self.tableView.scrollEnabled = YES;
}
return self;
}
然后我返回mySearchBar
委托viewForHeaderInSection:
方法。
那有什么问题?