Reputation: 4962
I am programmatically presenting a view controller (SavedGames.swift -> OnePlayer.swift), and I cannot figure out how to change the array in the view controller I am presenting (OnePlayer.swift) in the original controller (SavedGames.swift). I want to change tableData in OnePlayer in the block of code in SavedGames.swift.. Hope that makes sense
SavedGames.swift:
if let resultController = storyboard!.instantiateViewControllerWithIdentifier("OnePlayer") as? OnePlayer {
presentViewController(resultController, animated: true, completion: nil)
//in OnePlayer, set tableData to this tableData: [String] = ["one", "two", "three"]
}
OnePlayer.swift:
var tableData: [String] = ["zero", "zero", "zero"]
Upvotes: 1
Views: 71
Reputation: 3000
Do this
if let resultController = storyboard!.instantiateViewControllerWithIdentifier("OnePlayer") as? OnePlayer {
resultController.tableData = ["zero", "zero", "zero"]
presentViewController(resultController, animated: true, completion: nil)
//in OnePlayer, set tableData to this tableData: [String] = ["one", "two", "three"]
}
Upvotes: 1