开发者

UISearchBar Not appearing

I have view controller, into the view i have put a table view, and a search bar into the table's header... the search bar is not showing up, just the empty table view.

Do i need to do something additional? I'm pretty sure its to do wi开发者_如何学Goth the view outlet of the UIViewController, set to View...

Thanks


For anyone else who may be landing on this question, I had a very similar situation where a UITableViewController with a UISearchBar added to it wasn't displaying. If you find yourself in this situation, double check that you are actually calling:

initWithNibName:@"MyNibName" bundle:nil

to init your view controller instead of the common Table View init of:

initWithStyle:UITableViewStylePlain

I was foolishly adding the search bar to the Nib, and then loading it with the style init (which skips the Nib entirely and loads the table view from scratch)


try setting the tableHeaderView of your tableView to your searchBar.

self.tableView.tableHeaderView = searchBar;

if you are using IB, be sure to connect the outlets so that it gets referenced.


Try this,l it worked for me:

- (void)viewDidAppear:(BOOL)animated {
     [super viewDidAppear:animated];
     self.tableView.tableHeaderView = _searchBar;
     [_searchBar becomeFirstResponder];
}

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
     [_searchBar resignFirstResponder];
     self.tableView.tableHeaderView = _searchBar;
}

-(void) scrollViewDidScroll:(UIScrollView *)scrollView 
{
    searchBar.frame = CGRectMake(0,MAX(0,scrollView.contentOffset.y),320,44);
}


If you set your view controller as a part of tabbar controller, besides "Class" property in IB set the "NIB name" property. It takes me several hours to figure it out.


Fixed using a UISearchBar with controller.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜