Hide UITableView search bar by default when in a navigation controller

前端 未结 5 976
萌比男神i
萌比男神i 2021-02-03 14:05

I\'ve read multiple posts on this but it\'s not working properly for me. I\'m using the latest 4.2 SDK.

The code I have is

self.tableView.contentOffset =         


        
5条回答
  •  后悔当初
    2021-02-03 14:42

    You can set the initial bounds of the table view inside viewDidLoad, so the search bar appears hidden at the beginning.

    You have to create the searchBar property and then use following code:

    - (void)viewDidLoad
    {
        //...
        CGRect bounds = self.tableView.bounds;
        bounds.origin.y = self.tableView.bounds.origin.y + searchBar.bounds.size.height;
        self.tableView.bounds = bounds;
        //...
    }
    

提交回复
热议问题