未声明的标识符"viewDidLoad"; [英] Undeclared identifier "viewDidLoad"

查看:129
本文介绍了未声明的标识符"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设置了不同的视觉元素.错误被标记在该行上.

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. The error is tagged on the line that sais..

-(void)viewDidLoad {

错误说明了这一点.

Use of undeclared identifier 'viewDidLoad'

您想要更多信息吗?

推荐答案

您不能在其他方法中使用该方法.

you cannot have method inside another method.

这是您代码的一部分

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

这篇关于未声明的标识符"viewDidLoad";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆