【问题标题】:UITableview with variable row height crashes on reorder具有可变行高的 UITableview 在重新排序时崩溃
【发布时间】:2012-07-26 10:44:09
【问题描述】:

似乎有一个UITableView 错误,创建了简单的UITableView 并将编辑模式设置为YES,所有行都有不同的高度。例如,

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {  
    if(indexPath.row == 0)
        return 58;
    else if(indexPath.row == 1)
        return 520;
    else
        return 100;
}

现在开始触摸对第二行应用程序崩溃的重新排序控制。 也许这些行高强制UITableView 从底部自动滚动一个不可见的UITableViewCell,但UITableView 应该已经处理了。

任何想法......

【问题讨论】:

  • 你用什么代码对行重新排序?
  • - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath { Item *item = [self.itemArray objectAtIndex:sourceIndexPath.row]; [self.itemArray removeObjectAtIndex:sourceIndexPath.row]; [self.itemArray insertObject:item atIndex:destinationIndexPath.row]; }

标签: iphone uitableview heightforrowatindexpath


【解决方案1】:

您需要更换它..不要删除并重新插入它..

[self.itemArray exchangeObjectAtIndex:sourceIndex
                                 withObjectAtIndex:targetIndex];
[self.tableView reloadData];

【讨论】:

  • 即使moveRowAtIndexPath方法的主体为空,应用程序也会崩溃。但如果所有单元格的大小相同,则不会发生崩溃。
  • 那你的数组数肯定有问题,检查一下!
  • array.count 没有问题。
猜你喜欢
  • 2015-08-24
  • 2020-12-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-08
相关资源
最近更新 更多