iphoneiosuitableviewbuttonsetediting

How to set editing button on UITableView that is a subview on iOS


I have a UIViewController which has a UITableView as a child besides other elements. I want to add editing support on that tableView with this simple line:

self.navigationItem.rightBarButtonItem = self.editButtonItem;

It works if I set this on UITableViewController view type, but obviously that does not work on tableView's that are subviews. Actually it shows the editing button but the edit action is not triggered.

Anyway if there is no elegant solution for that I will simply implement custom editing button.

Thanks!


Solution

  • I've just found a solution. Replacing self.editButtonItem with self.myTableViewController.editButtonItem like that:

    self.navigationItem.rightBarButtonItem = self.myTableViewController.editButtonItem;
    

    It works like a charm. Could it be more simple? :)