Yuvrajsinh Vala
Yuvrajsinh Vala

Reputation: 138

How to insert row in UITableview in iOS in swift by clicking Button?

How can i insert new row in UITableview by click event of button in IOS in swift? I tried my best to do this but my all code not works so please help to solve it.

Upvotes: 0

Views: 1140

Answers (1)

Rashwan L
Rashwan L

Reputation: 38833

In your button event just add the data to the array that you use to populate your tableView and then make a tableView.reloadData().

So your initial array

var data = ["One", "Two", "Three"]

Your button event:

@IBAction func addData(sender: AnyObject) {
    data.append("Four")
    tableView.reloadData()
}

Upvotes: 1

Related Questions