objective c UITableView delete selected rows
Posted by Eng.Ahmed AlSadiOct 13
xcode – iphone – objective-c
Hi;
if you want to know my way of deleting selected rows from table view so maybe you choose the easiest way to delete selected rows or cells from UITableView :
firstly , my preferred way is use [[ UITableView : indexPathsForSelectedRows ]count] to get the count of selected rows only , and [ UITableView : indexPathForSelectedRow ] to get first selected row ” to delete ” , so if you have an array of values to list on tableView , you can do like below :
|
1 2 3 4 5 6 7 |
//ExampleDB.com by AlSadi
int selectedCoun = [[tableView indexPathsForSelectedRows]count];
for (int i=0; i<selectedCoun; i++) {
NSIndexPath* tmpIndexPath = [tableView indexPathForSelectedRow];
[self tableView:tableView commitEditingStyle:UITableViewCellEditingStyleDelete forRowAtIndexPath:tmpIndexPath];
} |
and on [ tableView : commitEditingStyle : forRowAtIndexPath ] from UITableViewDataSource Protocol Reference under UITableViewCellEditingStyleDelete editing style do as below :
|
1 2 3 4 5 6 7 8 9 10 11 12 |
//ExampleDB.com by AlSadi
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
[myArray removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
}
} |
Related posts:
- objective c UITableView delete all rows table view xcode – iphone – objective c Hi; the example below show how to delete all...
- objective c table view index of selected row cell Xcode – iphone – objective c Hi, to get index of selected section and row...
- objective c iPhone edit table view Xcode – iphone – objective c Hi, to edit table view UITableView you can easily...
- objective c iphone delete file xcode – iphone – objective c Hi; the method “function” below is an example how...
- objective c get iTunes file sharing folder files with full path xcode – iphone – objective c Hi; the method “function” below show you how to...
Leave a Reply