【发布时间】:2012-06-22 00:25:30
【问题描述】:
我正在使用 fetchresultscontroller 返回不同的结果 (NSDictionaryResultType),它在每个部分中有多个部分和行。当我使用indexPathForSelectedRow 时,它返回null。这是我的代码:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"toDetailViewSeg"]){
WLDetailTableViewController *detailController =segue.destinationViewController;
WeightLiftingInfo *theInfo = [[_fetchedResultsController fetchedObjects] objectAtIndex:self.tableView.indexPathForSelectedRow.row];
detailController.muscleGroupInfo = [theInfo valueForKey:@"muscleGroup"];
detailController.specificExerciseInfo = [theInfo valueForKey:@"specificExercise"];
detailController.managedObjectContext = _managedObjectContext;
}
}
如何获得正确的索引路径??
【问题讨论】:
-
这个问题看起来非常相似 (link)。我不是 100% 确定,所以我不会投票决定关闭它作为重复。
-
请删除
if-statement中没有被执行的分支。 -
尝试使用
[sender indexPathForSelectedRow],正如评论对this answer的建议 -
标题非常相似,但我认为情况不同。 IndexPathForSelectedRow 工作得很好,直到我想获取不同的结果。我在想这可能与返回结果是 NSDictionary 有关??
-
我尝试了以下代码,它又可以工作了。谢谢您的帮助!
WeightLiftingInfo *theInfo = [_fetchedResultsController objectAtIndexPath:self.tableView.indexPathForSelectedRow];
标签: objective-c uitableview nsfetchedresultscontroller nsindexpath