我发现,如果您将表格 View 设置为编辑模式,则在删除一行后滚动表格时,单元格编辑控件(左侧的红色减号)处于随机状态(垂直或水平)滚动表格时在其余单元格上。大概是因为我正在重用这样的单元格:
cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
如何强制每个单元格的编辑控件处于正确状态?它应该始终处于默认水平状态,除非我点击它来删除单元格。
编辑:这是单元格代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"WhateverIdentifier";
MyCell *cell = nil;
//This IF statement fixes the problem, but then I'm not reusing the cells
if (!tableView.isEditing) {
cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
}
if (!cell) {
cell = [[[NSBundle mainBundle] loadNibNamed:@"MyCell" owner:self options:nil] objectAtIndex:0];
}
//customize cell
return cell;
}
最佳答案
您是否在自定义单元格的 prepareForReuse
方法中调用了 [super prepareForReuse]
?
这解决了我的问题。
关于ios - UITableView - 在编辑模式下重复使用单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17200540/