Nathan
Nathan

Reputation: 151

"Method definition not in @implementation context"?

I put this in X-code:

- (void)viewDidLoad {
    [super viewDidLoad];
 NSString *path = [[NSBundle mainBundle] pathForResource:@"DrinkArray" ofType:@"plist"];
 NSMutableArray* tmpArray = [[NSMutableArray alloc] initWithContentsOfFile:path];
 self.drinks = tmpArray;
 [tmpArray release];
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

And it says this on the first line:

"Method Definition not an @implementation context"

Could anyone help?

Upvotes: 0

Views: 2244

Answers (3)

gonzobrains
gonzobrains

Reputation: 8034

I accidentally used:

 #include <stdlib.h>

one time. I used

#import <stdlib.h>

and it seemed to work better.

I know you may not have done this in your particular situation, but I thought this might help others who view this question in the future.

Upvotes: 0

Vagrant
Vagrant

Reputation: 1716

Did you put "@implementation " at the beginning of your methods, and "@end" at the end of them? Objective-C is like a preprocessor that turns code into C and so it needs help knowing when to do special processing on your Objective-C methods.

You seem to be trying to create a new ViewController, but you are doing it like a C programmer, instead of an Objective-C programmer. You need to define a subclass of the ViewController class, which means you need an "@interface" section and an "@implementation" section.

You best plan of attack might be to tell X-Code to add a new file, and in the template-chooser dialog, tell it to make a subclass of UIViewController. That will structure the code correctly. You can also find many ViewController tutorials online.

Upvotes: 1

Carl Norum
Carl Norum

Reputation: 225012

You put that method in the wrong place in your source file. Look for a line that says @implementation and another that says @end. Put your method in between there.

Upvotes: 0

Related Questions