通过触摸禁用UITableViewCell选择,但通过方法调用启用

时间:2014-10-08 05:13:48

标签: ios objective-c uitableview touches

阻止用户在UITableView中选择单元格,但允许我的程序在表格视图上调用selectRowAtIndexPath:的最佳方法是什么?

我还希望UITableViewCell中的控件保持交互(即允许在UITableViewCell上调用touchesBegan:)。

如果我执行[tableView setAllowsSelection:NO],则调用selectRowAtIndexPath:不会执行任何操作。

2 个答案:

答案 0 :(得分:0)

我意识到当您以编程方式调用selectRowAtIndexPath:时,将不会调用委托方法willSelectRowAtIndexPath:。但是,如果用户点击一个单元格,则会调用此单元格。此方法可以返回nil以防止选择。

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    return nil;
}

这将确保只有selectRowAtIndexPath:的编程调用才会选择一行,而选择行的任何点按都不会。

答案 1 :(得分:0)

取消选中此框:在TableView和TableViewCell中启用用户交互

enter image description here

相关问题