Вот моя проблема, мне кажется, я не могу набрать 2 символа в строке поиска, и приложение не падает на меня. Первая работает как надо, но когда я ищу любую другую бабочку, кроме первой, CRASH! Пожалуйста помоги!
[FilterComList removeAllObjects];
[FilterImgList removeAllObjects];
[FilterSciList removeAllObjects];
[filteredComList addObjectsFromArray:buttComNameList];
[filteredSciList addObjectsFromArray:buttSciNameList];
[filteredImgList addObjectsFromArray:butterflyImages];
}else {
[filteredComList removeAllObjects];
[filteredImgList removeAllObjects];
[filteredSciList removeAllObjects];
for (NSString *string in buttComNameList) {
NSRange range = [string rangeOfString:searchText options:NSCaseInsensitiveSearch];
if (range.location != NSNotFound) {
[filteredComList addObject:string];
}
}
for (NSString *string in buttSciNameList) {
NSRange range = [string rangeOfString:searchText options:NSCaseInsensitiveSearch];
if (range.location != NSNotFound) {
[filteredSciList addObject:string];
}
}
for (NSString *string in butterflyImages) {
NSRange range = [string rangeOfString:searchText options:NSCaseInsensitiveSearch];
if (range.location != NSNotFound) {
[filteredImgList addObject:string];
}
}
}
[myButterflyTable reloadData];
}
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
_searchWasActive = NO;
[butterflySearchBar resignFirstResponder];
[self.tableView setFrame:self.view.bounds];
}
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar {
_searchWasActive = YES;
NSLog(@"began editing");
}
- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar {
_searchWasActive = NO;
NSLog(@"ended editing");
}
Методы делегирования таблицы ниже
- (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section
return [filteredComList count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
Defenitions *def = [[Defenitions alloc]init];
// Configure the cell...
//[self fetchedResultsController:[self fetchedResultsControllerForTableView:tableView] configureCell:cell atIndexPath:indexPath];
if (_searchWasActive) {
[def defineButterfly:[filteredComList objectAtIndex:indexPath.row] defineLatin: [filteredSciList objectAtIndex:indexPath.row] setImage:[filteredImgList objectAtIndex:indexPath.row]];
}else {
[def defineButterfly:[buttComNameList objectAtIndex:indexPath.row] defineLatin:[buttSciNameList objectAtIndex:indexPath.row] setImage:[butterflyImages objectAtIndex:indexPath.row]];
}
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
[cell.contentView addSubview:[def commonName]];
[cell.contentView addSubview:[def latinName]];
[cell.contentView addSubview:[def butterflyImage]];
return cell;
}