2010-05-24 39 views
0

我把這個X-代碼:「方法定義不在@implementation上下文中」?

- (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; 
} 

它說,這在第一行:

"Method Definition not an @implementation context" 

誰能幫助?

回答

1

你有沒有把「@implementation」在你的方法開始,「@end」在他們結束了嗎? Objective-C就像是一個將代碼轉換爲C的預處理器,因此它需要知道何時對Objective-C方法進行特殊處理。

你似乎是要創建一個新的視圖控制器,但你正在做它像一個C程序員,而不是一個Objective-C編程。您需要定義ViewController類的子類,這意味着您需要「@interface」部分和「@implementation」部分。

你最好的進攻計劃可能會告訴X-代碼中添加一個新的文件,並在模板選擇對話框,告訴它做的UIViewController的子類。這將正確構造代碼。您還可以在線找到許多ViewController教程。

+0

謝謝,我只是放錯了地方的自營權之前把它。我把它移動了幾行,它工作。 – Nathan 2010-05-24 22:11:59

0

你放錯了地方的方法在源文件中。找一條說@implementation,另一條說@end。把你的方法放在那裏。

0

我不小心用:

#include <stdlib.h> 

一次。我用

#import <stdlib.h> 

它似乎更好。

我知道在您的特定情況下,你可能沒有這樣做,但我認爲這可能幫助其他人誰在將來觀看這個問題。