How to delete a row from an UITABLEVIEW and insert it in a second UITABLEVIEW in iphone?
I have developed a program in iphone which manage cards, the main functionality is create cards (question, answer) and show them in a uitableview (this so far is working properly). Each card have two buttons namely: ok-false, my idea is that when the user click on ok button, this card will appear in a new uitable开发者_JS百科view2 and deleted from the uitableview1(I do not know how to do it). In advance I add a new attribute to my card table in sqlite namely counter which will increase anytime that the user click on ok, with the idea behind that when the counter increase then will perform the function that I need "delete from current uitableview and insert in new uitableview" if the user click false, then the card will be deleted from tableview2 and inserted in tableview1. I will appreciate any ideas folks.
Thanks!
Simply delete the row from table 1 when ok is tapped & add a row to table 2. Try something like-
[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];
Now add the same row to table 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,
Akshay
精彩评论