tags:

views:

178

answers:

2

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?

+1  A: 

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.

Vagrant
Thanks, I just misplaced an import and put it right before. I moved it up a few lines and it worked.
Nathan
A: 

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.

Carl Norum