tableView でいくつかのデータを検索するための UISearchBar があり、検索後、行を選択して detailViewController を開きます。これを行うには、行がインデックス パスを保持し、検索後に最初の indexPath を変更しないことが必要です。そうしないと、データベース内で適切な要素を見つけることができないからです。最初の indexPath を保持するにはどうすればよいですか? 他の方法はありますか?
-(void) searchExpositorsTableView{
[searchResult removeAllObjects];
//In this array there are the elements resulted after research
for (Database *currow in self.mutableArray){
NSLog(@"list of expositors %@", self.mutableArray);
NSRange titleResultsRange = [currow.name rangeOfString:self.searchBar.text options: NSCaseInsensitiveSearch];;
if (titleResultsRange.length >0) {
[searchResult addObject:currow.name];
/*While I build this new array every indexPath change and the database
can not track down the original items*/
}
}
NSLog(@"%@", searchResult);
}
-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if(canSelectRow){
NSLog(@"%d", indexPath.row);
/*the indexPath is new and the database can not track down the original items*/
return indexPath;
}else{
return nil;
}
NSLog(@"%d", indexPath.row);
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//Open wrong element
}