I'd like the tableview to insert a new row with a text that corresponds to a specific button i've pressed, but I'm not certain how to specify that in my code / UI.
Basically, i'd like the text "button #1 pressed" to appear when I press button #1, "button #2 pressed" to appear when I press button #2, etc. How can I configure that?
TableViewController.swift
import UIKit
class TableViewController: UITableViewController {
var myArray = ["button #1 pressed", "button #2 pressed", "button #3 pressed"]
override func viewDidLoad() {
super.viewDidLoad(
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.textLabel?.text = self.FruitVegArray[indexPath.row]
return cell
}
}
SubViewController.swift
import UIKit
class SubViewController: UIViewController {
@IBOutlet weak var button1: UIButton!
@IBOutlet weak var button2: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let tableVC = segue.destination as! TableViewController
}
@IBAction func button1action(_ sender: Any) {
}
@IBAction func button2action(_ sender: Any) {
}
}