[英]UITableView - reusing cells while in editing mode
我发现如果你将表格视图设置为编辑模式,在删除一行后滚动表格时,单元格编辑控件(左边的红色减号)处于随机状态(垂直或水平)滚动表格时的单元格。 大概是因为我正在重复使用这样的单元格:
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]
吗?
这解决了我的问题。
我刚刚检查了一个UITableView我很方便,我没有看到这个问题。 我正在使用dequeueReusableCellWithIdentifier:就像你一样(当然没有if语句)。 您是否正在做一些特殊的刷卡或删除多行或其他东西?
(我会把它作为评论,但还不能。一旦你解决了问题,我会删除它。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.