UITableView contentOffSet is not working properly

前端 未结 15 1799
滥情空心
滥情空心 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:30

    This worked for me:

    // contentOffset will not change before the main runloop ends without queueing it, for iPad that is
    dispatch_async(dispatch_get_main_queue(), ^{
        // The search bar is hidden when the view becomes visible the first time
        self.tableView.contentOffset = CGPointMake(0, CGRectGetHeight(self.searchBar.bounds));
    });
    

    Put it in your -viewDidLoad or -viewWillAppear

提交回复
热议问题