Reputation: 5711
I have one screen that supposes to show a UITableView in it. I wish to allow the user to edit this table view; i.e. add lines, delete lines and change their order.
I know how to do this when the table view is embedded in a UITableViewController that's embedded in a UINavigationController and therefore has a relevant property to add these "edit" and "new" buttons to the navigation bar.
How should I approach it if my table view is in a regular UIViewController and this VC is not embedded in a UINavigationController?
I couldn't find any tutorials with such an example (they all display the navigation controller embedment scenario which I already know and is not relevant to my case...)
Upvotes: 1
Views: 162
Reputation: 38
Simply set your UIViewController as the delegate and datasource of your tableView. If you look in the documentation, you'll find that there are many useful delegates methods.
Add your UIButton, set it's target method to your own where you'll add or or remove a row by using
[tableView beginUpdates];
[tableView insertRowsAtIndexPaths:rowArray withRowAnimation:UITableViewRowAnimationAutomatic];
[tableView endUpdates];
mostly the Inserting, Deleting, and Moving Rows and Sections section
Upvotes: 1