LOLXDXPLOL
LOLXDXPLOL

Reputation: 611

Edit and add button for UITableView in ViewController

I have a little problem, I want to add a function to two BarItems in my UINavigationBar, which is placed above the UITableView in a normal ViewController. I'm very new to programming so can you please give me the complete code that I need? The functions I want to have are:

  1. An edit button so I can delete and change the data of a cell (title + subtitle)
  2. An add button so I can add a new cell to my UITableView. Maybe also a function that points to another ViewController where I can type the data for Title and subtitle to save it afterwards.

Thanks!

Upvotes: 0

Views: 553

Answers (1)

AaoIi
AaoIi

Reputation: 8396

For editing record:

You cannot get the cell that your planning to edit using button on UINavigationController, the buttons should be placed at the same cell on your UITableview to edit that specific cell. and in this way you need custom UITableviewcell.

For creating new record :

First link the button to your UIViewController class as Action. You can append the array that your using to fill the UITableview and then call your UITableview like to refresh the data:

self.tableview.reloadData()

For presenting another UIViewController:

First drag new ViewController in your storyboard and link the button on the first ViewController into your new UIViewController and choose segue as "Show".

To save your data its a big topic you have either NSUserDefaults or CoreData so Google it.

Note : linking means by pressing ctrl-drag with mouse to your target.

Update :

Download your sample from here : https://yadi.sk/d/EJf610XWhkxDT

Upvotes: 3

Related Questions