Set UITableView content inset permanently

前端 未结 8 795
余生分开走
余生分开走 2020-12-07 12:24

In my app I have a UISearchBar under UINavigationBar so it is always visible to user. In that case I had to set contentInset with extr

8条回答
  •  佛祖请我去吃肉
    2020-12-07 12:44

    After one hour of tests the only way that works 100% is this one:

    -(void)hideSearchBar
    {
        if([self.tableSearchBar.text length]<=0 && !self.tableSearchBar.isFirstResponder)
        {
            self.tableView.contentOffset = CGPointMake(0, self.tableSearchBar.bounds.size.height);
            self.edgesForExtendedLayout = UIRectEdgeBottom;
        }
    }
    
    -(void)viewDidLayoutSubviews
    {
        [self hideSearchBar];
    }
    

    with this approach you can always hide the search bar if is empty

提交回复
热议问题