简体   繁体   English

未声明的标识符“ viewDidLoad”

[英]Undeclared identifier “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

Here is the updated code, some before, and everything after. 这是更新的代码,之前和之后的所有内容。 There's a lot more to the program but it is all just setting up different visual elements for a GUI. 该程序还有很多其他功能,但都只是为GUI设置了不同的视觉元素。 The error is tagged on the line that sais.. 错误标明在该行上。

-(void)viewDidLoad {

And the error sais this.. 错误说。

Use of undeclared identifier 'viewDidLoad'

Would you like more info?? 您想要更多信息吗?

you cannot have method inside another method. 您不能在另一个方法中包含方法。

this is part of your code 这是你的代码的一部分

    //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

change it to 更改为

    //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];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM