这个真是个坑,弄了两个小时了,才设置好,哎,废话不多说,下面请看代码::::
-(void)addContentView{
backView=[[UIView alloc] initWithFrame:CGRectMake(0, 64, WIDTH, 44)];
[self.view addSubview:backView];
self.tableview=[[UITableView alloc] initWithFrame:CGRectMake(5, 108+10, WIDTH-10, HEIGHT)style:UITableViewStyleGrouped];
self.tableview.backgroundColor=[UIColor whiteColor];
self.tableview.rowHeight=100;
self.tableview.delegate = self;
self.tableview.dataSource = self;
self.tableview.tableHeaderView.layer.masksToBounds=YES;
self.tableview.tableHeaderView.layer.cornerRadius=5.0;
[self.view addSubview:self.tableview];
//初始化搜索栏
_searchC = [[UISearchController alloc] initWithSearchResultsController:nil];
_searchC.searchBar.barTintColor=[UIColor colorWithRed:234/255.0 green:234/255.0 blue:234/255.0 alpha:1.0];
_searchC.delegate=self;
//是否隐藏导航
_searchC.hidesNavigationBarDuringPresentation = NO;
!!!!!!!! _searchC.dimsBackgroundDuringPresentation=NO;--------->设置蒙版时候必须在返回的时候也设置一次蒙版,否则搜索的搜索框会一直存在,即 _searchC.dimsBackgroundDuringPresentation=YES;!!!!!!!!!!
_searchC.searchBar.barStyle=UIBarStyleBlack;
//自适应
[_searchC.searchBar sizeToFit];
//提示信息
_searchC.searchBar.placeholder = @"请输入商品名称";
_searchC.searchBar.showsCancelButton=YES;
UIButton *canceLBtn = [_searchC.searchBar valueForKey:@"cancelButton"];
[canceLBtn setTitle:@"取消" forState:UIControlStateNormal];
[canceLBtn setTitleColor:NAVCOLOR forState:UIControlStateNormal];
//代理方法
_searchC.searchResultsUpdater = self;
_searchC.delegate=self;
[backView addSubview:_searchC.searchBar];
self.definesPresentationContext=YES;
}
#pragma mark -- 搜索方法
// 搜索时触发的方法
-(void)updateSearchResultsForSearchController:(UISearchController *)searchController
{
_searchArray=[readValueData getResultOfSearch:searchController.searchBar.text];
// 刷新列表
[self.tableview reloadData];
}
}
哎,真是一个大坑啊,坑死一大堆人,