[英]UITableView - reusing cells while in editing mode
I'm finding that if you set a table view into editing mode, upon scrolling the table after deleting a row the cell edit control (the red minus sign on the left) is in a random state (turned vertical or horizontal) on the rest of the cells as you scroll the table. 我发现如果你将表格视图设置为编辑模式,在删除一行后滚动表格时,单元格编辑控件(左边的红色减号)处于随机状态(垂直或水平)滚动表格时的单元格。 Presumably because I'm reusing cells like this:
大概是因为我正在重复使用这样的单元格:
cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
How can I force the edit control to be in the correct state for each cell? 如何强制编辑控件为每个单元格处于正确状态? It should always be in the default horizontal state unless I tap it to delete a cell.
它应始终处于默认的水平状态,除非我点击它以删除单元格。
EDIT: Here's the cell code: 编辑:这是单元格代码:
- (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;
}
Are you calling [super prepareForReuse]
in the method prepareForReuse
of your custom cell? 你在自定义单元格的
prepareForReuse
方法中调用[super prepareForReuse]
吗?
That resolved my problem. 这解决了我的问题。
I just checked in a UITableView I had handy, and I don't see that problem. 我刚刚检查了一个UITableView我很方便,我没有看到这个问题。 I'm using dequeueReusableCellWithIdentifier: as you are (without the if statement, of course).
我正在使用dequeueReusableCellWithIdentifier:就像你一样(当然没有if语句)。 Are you doing something special with swiping, or deleting multiple rows or something?
您是否正在做一些特殊的刷卡或删除多行或其他东西?
(I'd make this a comment but can't yet. I'll delete it once you've resolved your problem.) (我会把它作为评论,但还不能。一旦你解决了问题,我会删除它。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.