My goals is search bar on top my table that searches the track_tiles in Dictionary. This table was built by Parsed data into an NSDictionary. My Dictionary for the table looks like...
tracksDict: {
"Cold Calling" = (
"<Track: 0x5f39bc0>",
"<Track: 0x5f3a3e0>",
"<Track: 0x5f3a990>",
"<Track: 0x5f3ae80>"
);
"Gate Keeper" = (
"<Track: 0x5f3b3e0>",
"<Track: 0x5f3b980>",
"<Track: 0x5f3bed0>"
);
"Hot Calling" = (
"<Track: 0x5f3c390>"
);
}
Below is my attempt of making a searchTable...
- (void) searchTableView {
NSString *searchText = searchBar.text;
NSMutableArray *searchArray = [[NSMutableArray alloc] init];
searchArray = listOfItems;
NSLog(@"Sorted: %@", searchArray);
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"track_title contains %@", searchText];
[searchArray filterUsingPredicate:predicate];
[copyListOfItems addObjectsFromArray:searchArray];
[searchArray release];
searchArray = nil;
}
I figured out how to use NSPredicate to search Track.track_title. But if I delete my current search (change searchText), then it crashes.
For example, if I search "pro". The new copyListOfItems array is correct. With two items in my array. But if I were to delete the "o" in pro or press "search" it crashes. I need some kind of loop that fix this problem. Please and thank you.