我有一个UITableViewController
的子类。在viewDidLoad
方法中,我使用下面的代码来设置表视图的标题。在viewDidAppear
方法中,UI似乎就是我的意思。但是当我点击搜索栏的取消按钮时,一切都会消失。
// header view for table view
UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 100)];
headView.backgroundColor = [UIColor redColor];
UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44)];
searchBar.placeholder = @"placeholder";
self.searchDisplayController_iOS7 = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
self.searchDisplayController.delegate = self;
self.searchDisplayController.searchResultsDelegate = self;
self.searchDisplayController.searchResultsDataSource = self;
[headView addSubview:searchBar];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 50, self.view.frame.size.width, 40)];
label.text = @"label";
[headView addSubview:label];
self.tableView.tableHeaderView = headView;
这是将搜索栏和标签添加到表格视图标题的正确方法吗?