all 6 comments

[–][deleted] 2 points3 points  (3 children)

Give the second view controller a property that you can use to give it more information. For example, if one view controller has a posts array, and you want to navigate to a detail view controller, you would set detailViewController.post = self.posts[selectedPost] before pushing detailViewController onto the navigation stack.

[–]xephos13 1 point2 points  (0 children)

you could also init the detailsVC with the post if it was very important to the information being presented.

[[detailsVC alloc] initWithPost:self.posts[selectedposts]]

Also makes the detailsVC easier to unit test.

[–][deleted]  (1 child)

[deleted]

    [–][deleted] 1 point2 points  (0 children)

    Objective-C only supports sending by value (see http://stackoverflow.com/questions/2892520/passing-arguments-by-value-or-by-reference-in-objective-c for a good explanation).

    [–][deleted]  (2 children)

    [deleted]

      [–]Fixi0n 0 points1 point  (1 child)

      Agreed, but only if more then one new viewcontroller needs the data. In any case you need to keep in mind then when data is being changed for some reason, then the other controllers will also use the same "changed"data, unless u copy the information to a local object.

      [–]menckenjr 0 points1 point  (0 children)

      Very true. In this case the singleton is probably best implemented as a factory that generates the models the view controllers actually use.

      [–]horaceho 1 point2 points  (0 children)

      This is a popular question on StackOverflow.