目标c:跨部门交换细胞

时间:2015-01-28 02:57:22

标签: objective-c uitableview

我有一个tableview包含很多部分,在每个部分中,有一个单元格,我想要做的是,当进入编辑模式时,我将一个单元格拖放到另一个部分,我希望在拖动时完成后,目标部分中的原始单元格将自动交换到单元格移出的部分。

这是我测试的代码,但没有用

-(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath 
{
    NSInteger destRow=destinationIndexPath.row;
    NSInteger srcRow=0;
    NSIndexPath *srcIndexPath=[NSIndexPath indexPathForRow:srcRow inSection:destinationIndexPath.section];
    UITableViewCell *cell=[self.tableView cellForRowAtIndexPath:srcIndexPath];
    [cell.textLabel setText:@"aaa"];// test if I got right cell, the result is ok.

    NSIndexPath *trgIndexPath=[NSIndexPath indexPathForRow:0 inSection:sourceIndexPath.section];
    [self.tableView moveRowAtIndexPath:srcIndexPath toIndexPath:trgIndexPath];
}

请帮我检查是否有任何解决方案,谢谢!

0 个答案:

没有答案
相关问题