如何从UITABLEVIEW中删除一行并将其插入到第二个UITABLEVIEW中



我在iphone上开发了一个管理卡片的程序,主要功能是创建卡片(问题,答案)并在uitableview中显示它们(到目前为止工作正常)。每个卡有两个按钮,即:ok-false,我的想法是,当用户点击ok按钮,这张卡将出现在一个新的uitableview2和从uitableview1中删除(我不知道如何做到这一点)。在此之前,我在sqlite中添加了一个新属性到我的卡片表,即计数器,它将在用户点击ok时增加,其背后的想法是,当计数器增加时,它将执行我需要的功能"从当前uitableview中删除并插入新uitableview"如果用户点击false,那么卡片将从tableview2中删除并插入tableview1。我将感谢大家的任何建议。

谢谢!

当ok被选中&向表2添加一行。试试-

[self.tableView beginUpdates];
[self.list removeObjectAtIndex:index]; //index of the row on which ok was tapped
[self.tableView deleteRowsAtIndexPaths:indexPaths withRowAnimation: UITableViewRowAnimationNone]; //indexPaths is an array with a single NSIndexPath that corresponds to index
[self.tableView endUpdates];

现在将相同的行添加到表2-

[self.list2 insertObject:card atIndex:0]; //card is the same card that was deleted from table 1
NSIndexPath* indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
NSArray* arr = [[NSArray alloc] initWithObjects:indexPath, nil];
[self.tableView insertRowsAtIndexPaths:arr withRowAnimation:UITableViewRowAnimationNone];
[arr release];

HTH,

阿卡什

最新更新