在我的项目中,我使用带有神奇记录的核心数据。
我的搜索栏运行良好,但搜索后如果我点击我的表格视图的第一行,我会得到未过滤的表格的详细视图:
所以如果我有 3 个名为 A、B、C 的对象并搜索 C,在我的表中我只看到 C,但如果我点击我会得到 A 的详细视图。
所以我尝试编写一个方法来获取正确的 indexPath:
-(NSIndexPath*)giveMeSearchedObject:(UISearchBar*)searchBar showInRow: (int) row
{
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"nome CONTAINS [cd] %@", searchBar];
NSArray *arra = [Ricetta MR_findAllSortedBy:@"nome" ascending:YES withPredicate:predicate];
Ricetta*ctn = arra[row];
NSIndexPath* correctPath =arra[row];
return correctPath;
}
但是当我在 prepareForSegue 中调用这个方法来设置 indexPath 时,我不知道在“showInRow:”之后写了什么:
if (searching == YES) {
NSIndexPath *indexPath = [[NSIndexPath alloc]init];
indexPath = [[DataManager sharedClass]giveMeSearchedObject:self.mySearchBar.text showInRow:???;
DetailViewController*dvc = segue.destinationViewController;
dvc.indice =indexPath.row;
所以,也许方法不正确。
有人可以帮助我吗?
更新
@interface
@property (nonatomic, retain) NSFetchedResultsController *fetchedResultsController;
@end
@implementation
@synthesize fetchedResultsController;
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"showDetail"]) {
if (searching == YES) {
UITableViewCell*cell = (UITableViewCell*)sender;
NSIndexPath*indexPath = [self.tableView indexPathForCell:cell];
Ricetta*ricetta = [self.fetchedResultsController objectAtIndexPath:indexPath];
DetailViewController*dvc = segue.destinationViewController;
dvc.indice =indexPath.row;