Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Micah Elias
2,774 PointsSearching Friends
In the Build A Self Destructing Messaging App, is there any way to include a search bar in the Edit Friends View Controller so that I can search through the whole liSt of users that use my app?
2 Answers
Stone Preston
42,016 PointsYes, you can drag a search bar onto the header view of your table view controller in your storyboard. You will have to conform to UISearchBar protocol and implement your view controller as the delegate
add this property to your view controller after dropping the search bar into the header section of your table view in the storyboard by control clicking and dragging to your header file using the assistant editor
@property (weak, nonatomic) IBOutlet UISearchBar *searchBar;
You should also add the following delegate protocol declaration to your header
@interface SomeViewController : UITableViewController <UISearchBarDelegate>
You then need to set your view controller as the search bar delegate in your view controllersview did load
self.searchBar.delegate = self;
and implement whatever search bar delegate methods you need such as
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
you can find more info on these methods here
you can modify some of the settings of the search bar in your storyboard such as if it has a cancel button etc
Micah Elias
2,774 PointsDo you know the code for that?
Stone Preston
42,016 PointsI edited my answer to show the code you will need