Objective c &引用;方法定义不在@implementation context“中;?
我把它放在X代码中:Objective c &引用;方法定义不在@implementation context“中;?,objective-c,Objective C,我把它放在X代码中: - (void)viewDidLoad { [super viewDidLoad]; NSString *path = [[NSBundle mainBundle] pathForResource:@"DrinkArray" ofType:@"plist"]; NSMutableArray* tmpArray = [[NSMutableArray alloc] initWithContentsOfFile:path]; self.drinks = tmpArr
- (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"
有人能帮忙吗?您是否在方法的开头加了“@implementation”,在方法的结尾加了“@end”?Objective-C就像一个将代码转换为C的预处理器,因此它需要知道何时对Objective-C方法进行特殊处理
您似乎在尝试创建一个新的ViewController,但您是像一个C程序员一样,而不是一个Objective-C程序员。您需要定义ViewController类的子类,这意味着您需要一个“@interface”部分和一个“@implementation”部分
您最好的攻击计划可能是告诉X-Code添加一个新文件,并在“模板选择器”对话框中,告诉它创建UIViewController的子类。这将正确地构造代码。您还可以在线找到许多ViewController教程。您在源文件中将该方法放错了位置。找一行写着
@implementation
,另一行写着@end
。把你的方法放在两者之间。我不小心用了:
#include <stdlib.h>
#包括
一次。我曾经
#import <stdlib.h>
#导入
而且似乎效果更好
我知道您可能在您的特定情况下没有这样做,但我认为这可能有助于其他人在将来看待这个问题。谢谢,我只是错放了一个导入,并将其放在了前面。我把它向上移动了几行,它成功了。