Я работаю над проектом, который позволяет воспроизводить звук при выборе ячейки в виде таблицы. Чтобы сделать вещи немного проще, я реализовал функцию поиска. Проблема в том, что она работает не так. когда вы нажимаете на результат, звук, который воспроизводится, исходит из исходного массива, а не только отфильтрованного. Я знаю, что моя ошибка лежит где-то здесь, и я бы немного помог найти ее.Результаты поиска Flitering
//Create new Sound Object
Sounds *sound = nil;
//check to see whether the normal table or search results table is being displayed and set the Sound object from the appropriate array
if (tableView == self.searchDisplayController.searchResultsTableView) {
sound = [filteredSoundArray objectAtIndex:indexPath.row];
}else{
sound = [soundArray objectAtIndex:indexPath.row];
}
//Configure the cell
[[cell textLabel]setText:[sound name]];
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
NSString *selectedSoundFile = [[soundArray objectAtIndex:indexPath.row]name];
NSString *path = [[NSBundle mainBundle]pathForResource:selectedSoundFile ofType:@"mp3"];
if(path){
theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
[self.theAudio play];
}
if (tableView == self.searchDisplayController.searchResultsTableView) {
theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
[self.theAudio play];
}
}
Спасибо!
При изменении NSString * selectedSoundFile = [[soundArray objectAtIndex: indexPath.row] имя]; to NSString * selectedSoundFile = [[filterSoundArray objectAtIndex: indexPath.row] name]; Я получаю «NSRangeException» для пустого массива. – user1176046
Отфильтрованные звуки работают отлично! Но я получаю «NSRangeException», когда пытаюсь воспроизвести звук, который я не ищу. – user1176046
, пожалуйста, найдите мой отредактированный ответ выше – RAJA