tableview和searchbar组合且不遮住状态栏

来源:互联网 发布:python是面向对象语言 编辑:程序博客网 时间:2024/06/10 02:09

 tableview和searchbar组合且不遮住状态栏

关键代码:

-(void)viewDidLoad{

      [superviewDidLoad];

     //  self.table.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];//去除多余行

    //设置table内容的位置,要在创建searchbar之前设置

    if (self.table.style ==UITableViewStylePlain) {

        UIEdgeInsets contentInset =_table.contentInset;

        contentInset.top =25;

        [_tablesetContentInset:contentInset];

    }


    //创建search

    _searchcontroller = [[UISearchControlleralloc]initWithSearchResultsController:nil];

    _searchcontroller.searchResultsUpdater =self;

    _searchcontroller.dimsBackgroundDuringPresentation =NO;

    _searchcontroller.hidesNavigationBarDuringPresentation =NO;

    _searchcontroller.searchBar.frame =CGRectMake(self.searchcontroller.searchBar.frame.origin.x,self.searchcontroller.searchBar.frame.origin.y,self.searchcontroller.searchBar.frame.size.width,44.0);

    

    self.searchcontroller.searchBar.delegate = self;

    

    self.searchcontroller.searchBar.keyboardType = UIKeyboardTypeDefault;

    CGRect r=self.table.tableHeaderView.bounds;

    r.origin.y=-10;

    self.table.tableHeaderView.bounds=r;

    self.table.tableHeaderView =self.searchcontroller.searchBar;

    }


(图片内容是未修复之前)



0 0
原创粉丝点击