Jukebox Babe

Hello there! I am Johan Halin. I make apps and music. I post good stuff sometimes. You can also find me on Twitter. You can if you have questions or comments.

July 24, 2009 at 7:33pm
Home

Code snippet: UISearchBar in UINavigationBar

Here’s a code snippet I found somewhere after looking for a while that was really useful for me. It’s like the title says, a UISearchBar in a UINavigationBar. In my case, I have a UITableView in my navigation controller, but I didn’t want two huge bars in the top level of my navigation controller. Here’s the code:

searchBar = [[UISearchBar alloc] initWithFrame:self.tableView.bounds];
[searchBar sizeToFit];
searchBar.delegate = self;
self.navigationItem.titleView = searchBar;

Hope this is useful for someone. I might post more snippets if I think of anything that I haven’t found online that might be useful for someone.