重新排序行时,最后一行的源索引路径设置为“0”

时间:2012-05-09 22:18:44

标签: iphone objective-c ios cocoa-touch uitableview

有人遇到过这种情况吗?

当我从最底层到最顶层重新排序时,我遇到了崩溃。当iSourceIndexPath.row变为0时,会发生这些崩溃。我想知道我的iSourceIndexPath.row如何变为0,因为这是我总是选择的最后一行。任何线索?

- (NSIndexPath *)tableView:(UITableView *)iTableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)iSourceIndexPath toProposedIndexPath:(NSIndexPath *)iProposedDestinationIndexPath {
    NSIndexPath *aReturnIndexPath = iProposedDestinationIndexPath;
    if(iProposedDestinationIndexPath.row == 0) {
        aReturnIndexPath = iSourceIndexPath;
    }

    NSLog(@"iProposedDestinationIndexPath=%d iSourceIndexPath=%d aReturnIndexPath=%d",iProposedDestinationIndexPath.row,iSourceIndexPath.row,aReturnIndexPath.row);
    return aReturnIndexPath;
}

1 个答案:

答案 0 :(得分:0)

移动细胞后我忘了重新加载表格。除了定期处理细胞外,你应该这样做。

- (void)tableView:(UITableView *)iTableView moveRowAtIndexPath:(NSIndexPath *)iFromIndexPath toIndexPath:(NSIndexPath *)iToIndexPath {
    [self.tableView reloadData]
}