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
Patrick Wondrak
3,358 PointsRecipe App Setup Question
I am looking to make a cookbook app where essentially you just create your recipes and store them. So the first screen will be a table view of all of your recipes and a button to create a new one. When you create a new one, the first screen that shows up you enter the basic recipe info, then you hit "next" and enter ingredients, hit "next" and enter directions and when you save all of that info is linked and show up when you select the recipe from the main tableview that shows ALL of your recipes...
My question is how can you link the information (outlets) from all 3 tableviews back to 1 view that will contain all of the information. Thanks!
4 Answers
Keli'i Martin
8,227 PointsI assume you have some kind of class that defines what a "recipe" is in terms of your app. Clicking Add would create a new instance of that class and then, as you progress through the different views (they probably don't all need to be table views, right? :) ), you should be able to pass that instance to each view via the segue that you'll need to move between apps. Then, when all the information has been entered in, that instance would get stored into some kind of container, which you should be presumably using to populate your main table view.
I'm basically just shooting from the cuff here, but that should be generally how you would accomplish that. Hope that gives you some ideas!
Patrick Wondrak
3,358 PointsThanks! Yes, I have a class that defines what a "recipe is" just trying to work through the logistics. The first/main screen is a tableview that shows all of the recipes. Every other screen after that will be just a UIViewController with labels and text fields and such. I was able to add a new recipe and save all of my data when I was juts working with the "Basic Info" Screen because it was 1 screen. I couldn't figure out how to get 3 separate views to all sync and save their data onto the "Recipe Information" view.
Steven Deutsch
21,046 PointsHey Patrick Wondrak,
You will need an initial view displaying a table view. I would then create a button at the top of that view that allows the user to add a new recipe. This will transition them to another view where they can enter the information for the recipe into text fields. Once they've filled out all of the fields and press the create recipe button, you want to grab all the information from those text fields on the button press. You will assign the information to the respective properties of your recipe object.
Now, you face the problem of getting this data back to your table view on the other view. You could just make a global recipe array to store the data at the top of your add a recipe view. Then your main view controller would be able to access it to populate the table view. However, this is not really the best practice. Better solutions would be using a segue on the add recipe button to pass back the information, storing the data in NSUserDefaults, or via CoreData. The later two have the added benefit of being persistent storage methods, this way when your user closes the app, the data will still be there.
If you have an email I can contact you at, I will send you an invitation to my Slack channel. I would be more than happy to walk you through this sometime in greater detail :)
Good Luck
Patrick Wondrak
3,358 PointsThat'd be great...my email is patrick.wondrak@gmail.com
Steven Deutsch
21,046 PointsInvite sent :)