Im making to do list-app which consist of 2 View Controllers one with table view hold an array and display it and second one with a textField, a button function to append the text field's text to the array to display the new appended string it in the first view controller heres my code:
class ViewController: UIViewController,UITableViewDataSource,UITableViewDelegate {
@IBOutlet weak var tableView: UITableView!
var exmpArray = ["DDDD","rrr","TTT"]
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
@IBAction func addBtnBar(_ sender: Any) {
performSegue(withIdentifier: "showMe", sender: nil)
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return exmpArray.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell")
cell?.textLabel?.text = exmpArray[indexPath.row]
return cell!
}}
and the second one is:
class SecondViewController: UIViewController {
@IBOutlet weak var myTextField: UITextField!
var realAry:[String] = []
override func viewDidLoad() {
super.viewDidLoad()
}
let myObj = ViewController()
@IBAction func addBtn(_ sender: Any) {
myObj.exmpArray.append(myTextField.text!)
print(myObj.exmpArray)
}
after appending the new words it doesn't display in the first controller