0

I have an array: var initialArray. That appends every time the screen is tapped. This is done on ViewController 3

I have a table which displays the array in another view controller: ViewController2. However the issue is: use of unresolved identifier: initialArray.

How can I get ViewController2 to recall variables from ViewController3?

class ViewController2: UIViewController, UITableViewDelegate, UITableViewDataSource {

@IBOutlet weak var tableView: UITableView!



override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.

    tableView.delegate = self
    tableView.dataSource = self


}
//How many rows
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return initialArray

//////use of unresolved identifier: initialArray

}
//What goes in each cell
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = UITableViewCell()
    print(indexPath.row)

    cell.textLabel?.text = initialArray[indexPath.row]

//////use of unresolved identifier: initialArray

    return cell
}
Lucas
  • 65
  • 2
  • 10
  • I think your question is duplicated with [this](http://stackoverflow.com/questions/28390528/pass-one-variable-from-one-viewcontroller-to-another-viewcontroller) – nynohu Nov 09 '16 at 00:29
  • 1
    Possible duplicate of [Pass variables from one ViewController to another in Swift](http://stackoverflow.com/questions/24044108/pass-variables-from-one-viewcontroller-to-another-in-swift) – JLONG Nov 09 '16 at 00:32
  • Each view controller needs its own properties. – rmaddy Nov 09 '16 at 00:34
  • @Lucas where are you declare initialArray . you should declare it ViewController2 – Nazmul Hasan Nov 09 '16 at 02:14
  • @Lucas or Define your initialArray outside the classes to access publicly – Nazmul Hasan Nov 09 '16 at 02:17
  • Please follow this link http://stackoverflow.com/questions/25522912/passing-data-back-from-view-controllers-xcode – Harish Singh Nov 09 '16 at 11:15
  • If your trying to pass variables from a view controller to a previous view controller you can try an unwind segue, and use prepare for segue, and set up your variables in callback. – zsteed Nov 17 '16 at 20:37

0 Answers0