1

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"]
2
  • I basically want to override OnePlayer tableData with the tableData array in SavedGames upon load, from the SavedGames class. Commented May 11, 2015 at 6:48
  • i am ready to help you. i know the logic. but you can write the code for that... in swift. Commented May 11, 2015 at 7:13

1 Answer 1

1

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"]
        }
Sign up to request clarification or add additional context in comments.

2 Comments

If both tableData are of same type, then resultController.tableData = self.tableData
@JoshO'Connor, Accept the answer so that it will help others as the right answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.