I am trying to use a search bar for input, but I want to ensure the input is in a certain format. So based on a list I need the user to start typing and have suggestions pop up that can be clicked on. Similar to many flight tracking apps that recommend airports that you can tap on and add.
Asked
Active
Viewed 33 times
0
-
How many possible answers are there? – Audun Kjelstrup Mar 03 '14 at 19:15
-
There are hundreds of answers – user1828081 Mar 03 '14 at 19:33
-
How are they stored? CoreData? Plist? – Audun Kjelstrup Mar 03 '14 at 19:34
-
I am planning on plist but I could change that. – user1828081 Mar 03 '14 at 19:35
1 Answers
0
This method from UISearchBarDelegate will be useful.
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
NSPredicate *searchPredicate = [NSPredicate predicateWithFormat:@"term BEGINSWITH[cd] %@", searchText];
[self.searchResults filterUsingPredicate:searchPredicate];
[self.tableView reloadData];
}
If there are too many results to load all of them into memory, consider forcing the user to enter at least 1 character before loading
if ([searchText length] && [searchText length] < 2) {
// Load answers matching search text. Only useful for BEGINSWITH predicate
return;
}
Replace BEGINSWITH
with MATCHES
or CONTAINS
if you want to match within an answer

Audun Kjelstrup
- 1,430
- 8
- 13
-
See this answer from SO: http://stackoverflow.com/questions/3921902/how-to-add-and-get-the-values-from-plist-in-iphone-sdk – Audun Kjelstrup Mar 03 '14 at 19:46