UITableView contentOffSet is not working properly

前端 未结 15 1751
滥情空心
滥情空心 2020-12-14 01:48

In viewWillAppear, I have added UISearchBar as my headerview of UITableView. When view loads, I hides UISearchbar under <

15条回答
  •  囚心锁ツ
    2020-12-14 02:32

    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

提交回复
热议问题