J'essaie de faire apparaître une alerte indiquant "Aucun enregistrement trouvé" si l'utilisateur effectue une recherche et que le prédicat renvoie zéro.Essayer de faire apparaître un UIAlert si mon prédicat de recherche renvoie zéro
J'ai essayé, mais l'alerte n'est jamais appelée. Je viens d'avoir une tableview vide.
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
if (self.sBar.text != nil){
NSPredicate *template = [NSPredicate predicateWithFormat:@"name contains[cd] $SEARCH OR optionOne contains[cd] $SEARCH OR optionTwo contains[cd] $SEARCH"];
NSDictionary *replace = [NSDictionary dictionaryWithObject:self.sBar.text forKey:@"SEARCH"];
NSPredicate *predicate = [template predicateWithSubstitutionVariables:replace];
[fetchedResultsController.fetchRequest setPredicate:predicate];
}
[[fetchedResultsController fetchedObjects] count];
if (fetchedResultsController.fetchedObjects != nil) {
//do nothing
} else {
//display alert
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"No records match."
delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
NSError *error = nil;
if (![[self fetchedResultsController] performFetch:&error]) {
// Handle error
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort(); // Fail
}
[self.myTable reloadData];
[sBar resignFirstResponder];
}
mis à jour avec le nouveau code – RyeMAC3