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

Assume we are creating an app to display random quotes. So far our app has a label and a button that have been added to the view. We need to create an 'IBAction' for our button. Please define a method called 'buttonPressed' and make sure it returns an 'IB

Can I get some help here? I feel stupid but its just not coming to me.. any help would be great.

2 Answers

Amit Bijlani
STAFF
Amit Bijlani
Treehouse Guest Teacher

As mentioned in the video. You need to implement a method called buttonPressed that returns IBAction.

- (IBAction) buttonPressed {
   // task 2 code will go inside this method

}

Thanks Amit!

I dont remember hearing anything about methods. I apologize and dont wanna sound dumb!

import "THViewController.h"

@implementation THViewController (IBAction) buttonpressed { self.buttonPressed.text = @"buttonPressed"; } @end

I cannot figure this out

Amit Bijlani
Amit Bijlani
Treehouse Guest Teacher

No need to apologize. It's always confusing and scary when you are learning something new, which is why we have the forum. In the video when you created the IBAction the method was created for your within the .h and the .m files. In the code challenge you are asked to write out the method manually. The name of the method is buttonPressed. What I wrote above is the answer for task 1.

For task 2 you are asked to assign a string to the label property named quoteLabel.

- (IBAction) buttonPressed {
self.quoteLabel.text = @"The road to success is always under construction";
}

If you are getting confused with the syntax and language then I highly recommend taking our [Objective-C Basics](https://teamtreehouse.com/library/objectivec-basics) and then you can come back do this course.

I think ui causes some confusion because when you hit preview with the correct method skeleton built, it will kick back an error:

http://screencast.com/t/PWZYEEEtFYd

If I say 'Check Work' it will accept it.