未声明标识符“viewDidLoad”

//Objects list //objects scroll UIScrollView *objects; objects=[[UIScrollView alloc]initWithFrame:CGRectMake(0,80,512,688)]; objects.showsVerticalScrollIndicator=YES; objects.scrollEnabled=YES; objects.userInteractionEnabled=YES; objects.backgroundColor = [UIColor clearColor]; [self.view addSubview:objects]; [objects setUserInteractionEnabled:YES]; [objects setCanCancelContentTouches:YES]; objects.contentSize = CGSizeMake(512,689); //divider UIButton *divider = [UIButton buttonWithType:UIButtonTypeCustom]; [divider setBackgroundImage:[UIImage imageNamed:@"white.png"]forState:UIControlStateNormal]; divider.frame = CGRectMake(300, 0, 1, 768); [divider setTitle:@"" forState:UIControlStateNormal]; [self.view addSubview:divider]; divider.adjustsImageWhenHighlighted = NO; //array colors UIImage *color[3000]; //color setup color[0] = [UIImage imageNamed:@"item.png"]; UIImageView *originalImageView = [[UIImageView alloc] initWithImage:color[0]]; [originalImageView setFrame:CGRectMake(300, 0, 212, 62)]; [objects addSubview:originalImageView]; //array buttons UIImageView *button[3000]; //button setup button[0] = [[UIView alloc] initWithFrame:[originalImageView frame]]; UIImageView *maskImageView = [[UIImageView alloc] initWithImage:color[0]]; [maskImageView setFrame:[button[0] bounds]]; [[button[0] layer] setMask:[maskImageView layer]]; button[0].backgroundColor = [UIColor blueColor]; [objects addSubview:button[0]]; //add object button UIButton *plus = [UIButton buttonWithType:UIButtonTypeCustom]; [plus setBackgroundImage:[UIImage imageNamed:@"plus.png"]forState:UIControlStateNormal]; plus.frame = CGRectMake(394, 106, 25, 25); [plus setTitle:@"" forState:UIControlStateNormal]; [objects addSubview:plus]; plus.adjustsImageWhenHighlighted = YES; -(void)viewDidLoad { [super viewDidLoad]; UIButton *add = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [add addTarget:self action:@selector(aMethod:)forControlEvents:UIControlEventTouchDown]; [add setTitle:@"add new" forState:UIControlStateNormal]; add.frame = CGRectMake(100, 100, 100, 100); [self.view addSubview:add]; } - (void) aMethod:(id)sender { button[0].backgroundColor = [UIColor greenColor]; } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end 

这里是更新的代码,一些之前和之后的一切。 程序还有很多,但它只是为GUI设置不同的视觉元素。 错误被标记在sais的行上

 -(void)viewDidLoad { 

而错误是这个..

 Use of undeclared identifier 'viewDidLoad' 

你想要更多的信息?

你不能有另一种方法的方法。

这是你的代码的一部分

  //add object button UIButton *plus = [UIButton buttonWithType:UIButtonTypeCustom]; [plus setBackgroundImage:[UIImage imageNamed:@"plus.png"]forState:UIControlStateNormal]; plus.frame = CGRectMake(394, 106, 25, 25); [plus setTitle:@"" forState:UIControlStateNormal]; [objects addSubview:plus]; plus.adjustsImageWhenHighlighted = YES; -(void)viewDidLoad { [super viewDidLoad]; UIButton *add = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [add addTarget:self action:@selector(aMethod:)forControlEvents:UIControlEventTouchDown]; [add setTitle:@"add new" forState:UIControlStateNormal]; add.frame = CGRectMake(100, 100, 100, 100); [self.view addSubview:add]; } - (void) aMethod:(id)sender { button[0].backgroundColor = [UIColor greenColor]; } } // <----this should not be here 

改变它

  //add object button UIButton *plus = [UIButton buttonWithType:UIButtonTypeCustom]; [plus setBackgroundImage:[UIImage imageNamed:@"plus.png"]forState:UIControlStateNormal]; plus.frame = CGRectMake(394, 106, 25, 25); [plus setTitle:@"" forState:UIControlStateNormal]; [objects addSubview:plus]; plus.adjustsImageWhenHighlighted = YES; } // <--- should be here to end method -(void)viewDidLoad { [super viewDidLoad]; UIButton *add = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [add addTarget:self action:@selector(aMethod:)forControlEvents:UIControlEventTouchDown]; [add setTitle:@"add new" forState:UIControlStateNormal]; add.frame = CGRectMake(100, 100, 100, 100); [self.view addSubview:add]; } - (void) aMethod:(id)sender { button[0].backgroundColor = [UIColor greenColor]; }