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 trialKyungMoon Lee
202 PointsWhy is Label dragged to .h file and is Button dragged to .m file?
I don;t know why it is different from each other!
Jose Ramos
1,908 PointsJose Ramos
1,908 PointsI highly recommend taking the pre-requisite to this course, Objective C Basics. It will REALLY help in understanding these videos and I think you are severely hurting yourself if you don't go through them.
.h is seen as a 'declaration' file, where .m is seen as an 'implementation' file.
When you drag the connect the button 'Show Another Fun Fact' over to Viewcontroller.m, it creates a method, showFunFact. At first, we had nothing in this method (ie, clicking the button would do nothing). We initially added NSLog, which would print a string of our choice to the console when clicked.
Now, this may not be the best explanation, but the label is dragged to .h because we are DECLARING the label here (as a property). It is of the class UILabel and is declared as a pointer (the asterisk) so we can reference it. To 'implement' this label with the button, we need to do this in the .m file: the implementation file. This is done in the showFunFact method:
self.funFactLabel.text = @"another interesting fact!";
The way I try to look at it is this:
.h files you can declare stuff, but if you want to do cool shit with these things, you have to implement them in the .m files. I see .m files as 'under the hood'.