Ohad Regev
Ohad Regev

Reputation: 5711

iOS >> Creating an EDITABLE UITableView with no UINavigationController

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

Answers (1)

Ian Beaubien
Ian Beaubien

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.

http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewDelegate_Protocol/Reference/Reference.html

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];

please see http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableView_Class/Reference/Reference.html#//apple_ref/doc/c_ref/UITableView

mostly the Inserting, Deleting, and Moving Rows and Sections section

Upvotes: 1

Related Questions