以编程方式'触摸'UITableViewCell?

Jos*_*ane 1 iphone objective-c uitableview ipad

我需要以编程方式选择UITableViewCell,我试过这个:

NSIndexPath *selectedCellIndexPath = [NSIndexPath indexPathForRow:0 inSection:0];
        [table selectRowAtIndexPath:selectedCellIndexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
Run Code Online (Sandbox Code Playgroud)

但是,它只能直观地选择单元格,didSelectRowAtIndexPath除非您实际点击单元格,否则不会选择该单元格.

任何想法,有没有人经历过这个或有想法绕过这个或以不同的方式处理它?

Aar*_*man 9

在向selectRowAtIndexPath发送消息后,为什么不向didSelectRowAtIndexPath发送消息?代码应该如下所示:

NSIndexPath *selectedCellIndexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[table selectRowAtIndexPath:selectedCellIndexPath 
                   animated:YES 
             scrollPosition:UITableViewScrollPositionNone];
[table.delegate tableView:table didSelectRowAtIndexPath:selectedCellIndexPath];
Run Code Online (Sandbox Code Playgroud)