我有一个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:
。
这有什么不对?