是否可以将UISearchBar和UILabel添加到UITableView';iOS 7上的头是什么?

是否可以将UISearchBar和UILabel添加到UITableView';iOS 7上的头是什么?,ios,uitableview,uiviewcontroller,uisearchbar,Ios,Uitableview,Uiviewcontroller,Uisearchbar,我有一个子类UITableViewController。在viewDidLoad方法中,我使用下面的代码设置表视图的标题。在viewdide方法中,UI似乎就是我所想的。但当我点击搜索栏的“取消”按钮时,一切都消失了 // header view for table view UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 100)];

我有一个子类
UITableViewController
。在
viewDidLoad
方法中,我使用下面的代码设置表视图的标题。在
viewdide
方法中,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;

这是向表视图标题添加搜索栏和标签的正确方法吗?

问得好。。。面对同样的问题?@Shardul我使用了一种技巧方法来满足此规范。TableView被划分为多个部分,第0部分中的单元格用于显示标签内容。这样,搜索栏是表头视图中唯一的生成器