I have a search bar added in the user interface. The Searchbar is already set, and works, but I can’t figure out how to make it search content in the UITableView. Can I just remove the items that do not start with the characters typed in the search bar??
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
if (searchBar.text.length < 1) {
return;
}
else {
// Do search stuff here
}}
This code works, the else function is called. But I don’t know how to do it. I don’t want to create a whole new array just for that.
I’ll do you one better. This example will search as the user types. If your data is quite massive, you may want to implement it in
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBarlike you originally planned. Unfortunately, you need a second array, but it’s easy to code around it in the table:then update your delegate methods to show the data of the
filteredTableDataarray instead of the regular array when theisFilteredvar is set to YES.