ios - 禁用TableView单元格

标签 ios uitableview

如何禁用除UITableView的前三个单元格以外的所有单元格?

如果选择了一个禁用的单元格,则返回nil:

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {

if ( indexPath.row >= 3 ) {
    [[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:2 inSection:0]] setAlpha:0.5];
    return nil;
}

return indexPath; }

如何使禁用的单元格“可见”?
这可行,但我只能在启动时使用,因为滚动时每个单元格的indexPath都会更改(重复使用单元格):
for(int i = 3; i <= 100; i++) {
    [[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]] setAlpha:0.5];
}

最佳答案

最好在tableView:cellForRowAtIndexPath:中设置禁用单元的不透明度。正如@Parcs在their answer中正确说出的那样,您还可以在那里将禁用单元格的userInteractionEnabled设置为NO。

您可以忽略tableView:didSelectRowAtIndexPath:中不 Activity 单元格上的点击。

关于ios - 禁用TableView单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21560517/

相关文章:

ios - 在物理设备上测试时图像的白条和黑条

iphone - Obj-C,引用计数的对象在释放后使用吗?

ios - UITableView with UICollectionView in row weird scroll in different rows at the same time

ios - Swift 代码中的 SVPullToRefresh + SVInfiniteScrolling

iphone - UITableView 分页

ios - 为什么只有一个单元格返回零?

ios - 我希望我的 UILabel 遵循我的 UISlider 值

ios - 哪个事件用于检测 UITextfield 处于 null 状态

iphone - 在哪里存储 UIDocument 的预览?

ios - 将 UIWebView 转换为具有动态大小的 UITableViewCell