2013-06-19 140 views
4

我发现如果您将表视图设置为编辑模式,在删除一行后滚动表格时,单元格编辑控件(左侧的红色减号)位于在您滚动表格时其余单元格的随机状态(旋转垂直或水平)。大概是因为我重用细胞是这样的:UITableView - 在编辑模式下重用单元格

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; 
} 
+0

你能发布你的代码的更多细节? –

+0

发布了该问题的更新。 – soleil

+0

MyCell *类是否有任何自定义的东西? –

回答

0

我只是检查在一个UITableView我有用场了,我没有看到这个问题。我使用dequeueReusableCellWithIdentifier:就像你一样(当然没有if语句)。你是否在做一些特别的事情,比如滑动或删除多行或什么的?

(我会做这样的评论,但还不能,我会删除它一旦你解决你的问题。)

+0

不,只是标准的表格编辑。 – soleil

7

你叫的方法,您的自定义单元格的prepareForReuse[super prepareForReuse]

这解决了我的问题。

+0

AGGGGHHHHHHHHH我花了两周的时间看这个!!!!!!感谢您的快速解决方案。 – atreat

+0

谢谢,完美的解决方案;) –

相关问题