I'm trying to insert an UISearchBar to my Toolbar of my TableView but it fail to built my app (iOS5.1) with this error
UISearchBar embedded in UIBarButtonItems (Only available in iPad documents)
http://img.muse-gaming.org/file/1359259573-uisearchbar.png
And i really can't figure it out...
Any idea ?
That being said, it might be possible to make your own view that looks and works like a UIToolbar
that does allow a UISearchBar
.
Solution is that Use a navigation bar instead of a toolbar. Set the search bar to the navigation bar's title view.
Or Yu can add it Programmatically
self.searchBar.frame = CGRectMake(70, 3, 230, 44);
UIToolbar * searchToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0,0+20,[self view].bounds.size.width,52)];
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *infoButtonItem=[[UIBarButtonItem alloc]initWithTitle:@"Update" style:UIBarButtonItemStyleBordered target:self action:@selector(infoButtonClicked)];
UIBarButtonItem * searchBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:self.searchBar];
[searchToolbar setItems:[NSArray arrayWithObjects:flexibleSpace,infoButtonItem,searchBarButtonItem, nil] animated:YES];
[self.view addSubview:searchToolbar];