-1

Im new to programming and trying to build my own app, I wonder how Im I supposed to link the info I get from the addTask viewcontroller to the tableview cell? At the moment Im just trying to get the text from the textfield and Im going to add the other features later. What Im trying to do

CFRJ
  • 157
  • 1
  • 12

4 Answers4

0

Refer This :-

Create a global array add remove element from that array on click of your button

0

You can pass data from one view controller to another using Delegates. Check my ans here. You can set your table view class as delegate of your task view controller. Implement the protocol methods of task view controller get the data and reload table. Hope it helps. Happyy Coding!!

luckyShubhra
  • 2,731
  • 1
  • 12
  • 19
0

You can pass data using Delegation .

In Second ViewController

import UIKit

protocol secondViewDelegate: class {
   func passData(arrData : [Any])
   }

class SecondViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {

    weak var delegate: secondViewDelegate? = nil

        @IBAction func clickOnButton(_ sender: Any) {
            self.delegate.passData([]) // replace your array here 
         }
}

In FirstViewController

class FirstViewController: UIViewController, UITableViewDataSource, secondViewDelegate

    let objectSecondVC: SecondViewController? = storyboard?.instantiateViewController(withIdentifier: "secondVCID") as! SecondViewController?
            objectSecondVC?.delegate = self
            navigationController?.pushViewController(objectSecondVC?, animated: true)

Second ViewController Delegate Method in FirstViewController

func passData(arrData : [Any]){
// append to your main array
}
KKRocks
  • 8,222
  • 1
  • 18
  • 84
0

It seems like your add task view controller is connected with your table view controller though a segue. So when you moving back from add task view controller, you can use unwind to pass data back. Here is a detailed tutorial with simple instructions and pictures.

Fangming
  • 24,551
  • 6
  • 100
  • 90