UISearchController搜索

这个真是个坑,弄了两个小时了,才设置好,哎,废话不多说,下面请看代码::::

-(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];

}

}

哎,真是一个大坑啊,坑死一大堆人,





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

冉然

你的鼓励对我很重要

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值