I'm using the search bar to grab the text the user inputs and then use that to filter through an NSArray, and then assign the newly constructed array to the specified class' array property. Code below:
-(void)updateSearchResultsForSearchController:(UISearchController *)searchController{
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF beginswith[c] %@",searchController.searchBar.text];
NSArray *temp = [_array filteredArrayUsingPredicate:predicate];
_resultViewController.dynamicArray = temp;
}
But my resultViewController's tableView isn't displaying any data. However, if I use the below, it works:
-(void)updateSearchResultsForSearchController:(UISearchController *)searchController{
NSArray *temp = [[NSArray alloc]initWithObjects:@"hello",@"bye",@"why",@"okay", nil];
_resultViewController.dynamicArray = temp;
}
I'm not quite sure how to fix this problem. It seems like when I assign _resultViewController's dynamic array to temp, temp hasn't been set yet when working with filtering the array. But it works fine in the second case, so I know the rest of the code is right.
Thoughts?