Je suis face à un problème dans la mise en œuvre de la fonctionnalité de recherche dans le tableau Vues ... Voici le code que je suis à la recherche ... La mise en œuvredans la recherche des vues de table
- (void) searchTableView {
NSString *searchText = searchBar.text;
NSMutableArray *searchArray = [[NSMutableArray alloc] init];
searchArray = [data boats];
for(Boat *boat in searchArray)
{
NSRange titleResultsRange = [[boat boatName] rangeOfString:searchText options:NSCaseInsensitiveSearch];
if (titleResultsRange.length > 0)
[copyListOfItems addObject:boat];
}
[searchArray release];
searchArray = nil;
}
Lorsque la la barre de recherche commence à être édité, j'appelle cela ...
- (void)searchBar:(UISearchBar *)theSearchBar textDidChange:(NSString *)searchText {
//Remove all objects first.
[copyListOfItems removeAllObjects];
if([searchText length] > 0) {
[ovController.view removeFromSuperview];
searching = YES;
letUserSelectRow = YES;
self.tableView.scrollEnabled = YES;
[self searchTableView];
}
else {
[self.tableView insertSubview:ovController.view aboveSubview:self.parentViewController.view];
searching = NO;
letUserSelectRow = NO;
self.tableView.scrollEnabled = NO;
}
[self.tableView reloadData];
}
et i affecter la valeur à la ligne de table à l'aide ...
if(searching)
{
Boat *copyboat = [copyListOfItems objectAtIndex:[indexPath row]];
cell.textLabel.text = [copyboat boatName];
NSLog(@"%@", [copyboat boatName]);
}
else {
Boat *fullboat =[data.boats objectAtIndex:[indexPath row]];
cell.textLabel.text =[fullboat boatName];
}
Mais quand je commence à taper les valeurs dans la barre de recherche, l'application se bloque. J'ai des erreurs différentes quand je tape différents alphabets. Je reçois des erreurs comme. * Mettre fin application en raison d'exception uncaught 'NSRangeException', raison: '* - [NSMutableArray objectAtIndex:]: index 6 au-delà des limites [0 .. 5]'
ou
* Mettre fin app due exception non interceptée 'NSRangeException', raison: '* - [NSMutableArray objectAtIndex:]: index 0 au-delà des limites pour tableau vide'
Parfois, il montre aussi EXEC_BAD_ACCESS aussi ... Je suis vissé maintenant. Quelqu'un peut-il s'il vous plaît dites-moi ce que l'erreur est exactement ... ???