我有一个 UISearchBar 来搜索 tableView 中的一些数据,然后在搜索后选择一行来打开 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
}