Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS

I am stuggling to pass one of the iOS challenges please help

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 'IBAction'.

import "THViewController.h"

@implementation THViewController

  • (IBAction)buttonPressed;

@end

However, I am not getting it correct. Please help.

Stone Preston
Stone Preston
42,016 Points

please link to the specific challenge you are referring to

3 Answers

Stone Preston
Stone Preston
42,016 Points

it looks like you are currently putting this code in the implementation file for this class. You need to put your method declaration in the interface file (.h) not the implementation (.m). There should be a tab where you can switch between files in the challenge engine. other than that your code looks correct

Hi..

am stuck on the same task.. the reason being i cannot switch to the .m file to finish the code.. how do i get into .m file?

Thank you Stone.. I managed to pass the task

Stone Preston
Stone Preston
42,016 Points

Fatemah Manji, please post a link to the challenge you are having trouble with

Scott LaForest
Scott LaForest
5,600 Points

Like Stone said, usually methods are declared in the .h file. However if I remember on the code challenges you can't change between .h (interface) and .m (implementation) files. But when you define methods in the .m file the syntax is a little different. To declare in the .h file you use what you have i.e.

  -(IBAction) buttonPressed;

and then in the .m file you need {} on the end like so:

-(IBAction) buttonPressed{
   //stuff to do when our button is pressed
}

Without seeing the question I can't tell for sure but hopefully this helps.