peterchen149 2015-03-11 13:50 采纳率: 0%
浏览 2423

怎么获取被选中cell的下一个cell?

我想在一个cell被选中时改变下一个cell的detailtable;

我试了下面的方法

     NSIndexPath *indexPath = [.myTableView indexPathForSelectedRow];
        UITableViewCell *cell =[.myTableView cellForRowAtIndexPath:indexPath]
                NSUInteger i = indexPath.row +1;
                   NSIndexPath *nextCellIndexPath = [NSIndexPath indexPathWithIndex:i];
                    UITableViewCell *nextCell = [addOperationViewController.myTableView cellForRowAtIndexPath:nextCellIndexPath];

但是报错
Assertion failure in -[NSIndexPath row], /SourceCache/UIKit_Sim/UIKit-3318.16.14/UITableViewSupport.m:2813
2015-03-11 21:46:19.544 Project[8647:228767] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid index path for use with UITableView. Index paths passed to table view must contain exactly two indices specifying the section and row. Please use the category on NSIndexPath in UITableView.h if possible.'

请问怎么解决?

  • 写回答

1条回答 默认 最新

  • harder321 2015-03-12 02:01
    关注

    写错了:
    NSIndexPath *ipath = [tableView indexPathForSelectedRow];
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:ipath];
    NSUInteger i = ipath.row +1;
    NSIndexPath *nextCellIndexPath = [NSIndexPath indexPathForRow:i inSection:0];//这里的问题
    UITableViewCell *nextCell = [tableView cellForRowAtIndexPath:nextCellIndexPath];

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器