I just inserted a table into a normal UIViewController and connected the delegate and source components with the file's owner. Everything works fine when i insert data into the table rows. but now i am trying to find out how rows can be deleted.
I just looked at a lot of other posts, but couldn't find the right solution.
I tried to insert a asseccory button for each row in the table:
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
i even found the method that will be called when the accessory button is pressed:
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath{
NSLog(@"Accessory pressed");
//[self tableView:tableView willBeginEditingRowAtIndexPath:indexPath];
//[self tableView:nil canEditRowAtIndexPath:indexPath];
//[self setEditing:YES animated:YES];
}
Inside the log the message is printed, but no one of the methods that i tried to call (the commented one) did change the view to the edit mode. How can i solve this problem?
Here is a Screenshot of the UIViewController. I haven't integrated a navigationController.
In order to enable edit mode for table view, you can call edit method on
UITableView
as,You have to implement
tableView:commitEditingStyle:forRowAtIndexPath:
method to enable the deleting of rows. In order to delete the rows you need to usedeleteRowsAtIndexPaths:withRowAnimation:
method.For eg:-
For more details check the apple documentation here.
I could just solve the problem for deleting the rows. To make it work i inserted like ACB told me, the following methods:
I found this solution on cocoapi.wordpress.com/tag/caneditrowatindexpath
But i still have just one problem. If somebody enters in editing mode, and won't delete a row, there is no possibility, to turn the editing mode off again. If you switch the view and come back again it autmatically stops, but otherwise its not possible because i don't have a NavigationController inserted.
Is there a way, to access the state of the Deletion Control on the left of the row while editing? it would be useful to detect if somebody turned the deletion off again to jump out of editing mode.
It might not fit the apple user guide, but im just on my first project and it should just work.