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

Weather App: Tap on a label or view to show more info, tap again there to show less info.

Some weather apps have to ability to show more information about the weather when you tap somewhere there. So, if you tap on a label or a view, more information appears and when you tap again there, less information is shown. Can someone give an an idea how to do this?

Thank you!

1 Answer

Nathan Tallack
Nathan Tallack
22,164 Points

A great way to lean is take a look at the templates that come with Xcode.

Open a new project, make an IOS project and choose Master-Detail Application.

Now take a look at how there are two view controllers. One is the master, that is the same as when you have a single view application template. The other is detailed view controller.

Open your assistant editor (two circle button in top right, opens split screen) and open the main storyboard on the right and the master view controller on the left. See in your storyboard how you have a segway (the line) between master view (top right) and your detail views navigation controller (bottom left). That is what transitions from one view to another. In the default template example it is using a tap on the table row to transition across. It is quite clever because you can carry the detail on which row is tapped across to the detail view controller so the detail is relevant to the row.

If you made a weather app out of this template, each of your day forecasts would be a row in the main view and selecting one of those days would go to the detail forecast for that day in the detail view.

Infact that is exactly how the apple weather app is made. Using that very template.

It is quite a learning curve, but one that is very easy to navigate if you use the right templates from the start and build upon them rather than trying to do it all from the ground up. :)

The issue is: "My label untapped shows only the current weather, when I tap it, it shows: real feel temp, humidity, etc, and if I tap it again the label shows only the current weather". Do you understand it?

Nathan Tallack
Nathan Tallack
22,164 Points

Oh right, yeah. It is not that you want to open another view it is that the content is not showing right.

Could you push your code up to github or share it in another way and I would be happy to take a look at it for you and see if I can help work it out. :)