【问题标题】:IndexPathForSelectedRow returns nullIndexPathForSelectedRow 返回 null
【发布时间】: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


【解决方案1】:
WeightLiftingInfo *theIndo = [_fetchedResultsController objectAtIndexPath:self.tableView.indexPathForSelectedRow];

这似乎是答案。它提供了正确的索引路径,看起来像一个集合 [x,y] 而不是单个整数。 (这是我的解释,可能是错误的)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-21
    相关资源
    最近更新 更多