Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

How to push data (variables) to another view controller.

I'm building a camera app similar to Ribbit from Treehouse, but I want to be able to add recipients from a separate view controller. Then I want to dismiss the view controller and have the recipients (and recipient Ids) 'attached' to the other view controller so it will send. So far, it's been a long arduous process for me.

Will this method be better executed by delegate? Or preparebySegue?

4 Answers

prepareForSegue

Just create an instance of the destination view controller and pass the variables

I create an instance in firstviewcontroller of secondviewcontroller, right? And firstviewcontroller has the property?

So, like this?

  • (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { ComposeViewController *composeViewController = segue.destinationViewController; composeViewController.recipients = self.recipients; }

Compose being the first view controller, recipients being the property (NSArray)

Yes, that should work.

recipients should be a property of composeViewController

Just to clarify, I'm trying to transfer the property from the recipientsViewController (the tableview) to the composeViewController (a uiviewcontroller). I want to dismiss 'recipientsVC' and have the selections send from compose. It'll still work?

Sorry, still new at this.