Search code examples
iphoneuitableviewheightforrowatindexpath

UITableview with variable row height crashes on reorder


There seems to be a UITableView bug, simple UITableView is created and the editing mode is set to be YES, all rows have varying height. For example,

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

Now on touching reorder control of second row application crashes. Perhaps these row heights enforce the UITableView to auto scroll an invisible UITableViewCell from the bottom, but UITableView should have handled it.

Any idea….


Solution

  • You need to exchange it..not remove and re-insert it..

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