Zac*_*her 6 uitableview uisearchbar uistoryboardsegue
我有一个时代的狄更斯让整个Core Data,Storyboard,UISearchBar三人组合在一起工作.最后用Core Data成功构建了表,用搜索文本缩小了项目,并修改了prepareForSegue,还有一个打嗝......
当我点击表格中的任何项目进入详细视图时,未经过滤的表格中的一切都很好.调用PrepareForSegue并完美显示细节.
当我搜索时,我的表被过滤了(我现在要过滤数组选项而不是第二个NSFetchedResultsController,但不是因为没有尝试!).
当我单击筛选列表中的某个项目时,将调用prepareForSegue并按下详细信息视图,但是,它始终从列表中的第一个项目中提取详细信息!
例如,如果我搜索"c"并且列表缩小为"查理"和"Cookie",当我选择"查理"时,我会看到"查理"的详细视图.当我选择"Cookie"时,不幸的是,我也看到了"查理"的详细视图
我假设prepareForSegue代码是问题(可能不正确?).这是代码:
SampleTVC *sampleDetailTVC = segue.destinationViewController;
sampleDetailTVC.delegate = self;
// Store selected Role in selectedRole property
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
// self.selectedRole = [self.fetchedResultsController objectAtIndexPath:indexPath];
if (savedSearchTerm){
self.selectedRole = [self.searchResults objectAtIndex:indexPath.row];
} else {
self.selectedRole = [self.fetchedResultsController objectAtIndexPath:indexPath];
}
NSLog(@"Passing selected role (%@) to SampleTVC", self.selectedRole.name);
sampleDetailTVC.role = self.selectedRole;
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激!
Zac*_*her 12
感谢Phillip Mills,答案是:
只需添加:
indexPath = [self.searchDisplayController.searchResultsTableView indexPathForSelectedRow];
Run Code Online (Sandbox Code Playgroud)
完整样本:
SampleTVC *sampleDetailTVC = segue.destinationViewController;
sampleDetailTVC.delegate = self;
// Store selected Role in selectedRole property
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
// self.selectedRole = [self.fetchedResultsController objectAtIndexPath:indexPath];
if (savedSearchTerm){
indexPath = [self.searchDisplayController.searchResultsTableView indexPathForSelectedRow];
self.selectedRole = [self.searchResults objectAtIndex:indexPath.row];
} else {
self.selectedRole = [self.fetchedResultsController objectAtIndexPath:indexPath];
}
NSLog(@"Passing selected role (%@) to SampleTVC", self.selectedRole.name);
sampleDetailTVC.role = self.selectedRole;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5517 次 |
| 最近记录: |