1

我正在尝试单击按钮移动子视图,但它崩溃并给了我-[MainGameDisplay openTimeChanger:]: unrecognized selector sent to instance 0x10e443d0

这就是我正在做的事情:

@interface:
UIImageView *changerBackground;
@implementation

timerView = [[UIView alloc] initWithFrame:CGRectMake(0, 278, 105, 27)];
[self.view addSubview:timerView];

changerBackground = [[UIImageView alloc] init];
[changerBackground setImage:[UIImage imageNamed:@"speedbackground.png"]];
changerBackground.frame = CGRectMake(-12 , 9, 105, 33);
[changerBackground setUserInteractionEnabled:YES];
[timerView addSubview:changerBackground];

UIButton *timerBackground = [UIButton buttonWithType:UIButtonTypeCustom];
[timerBackground setBackgroundImage:[UIImage imageNamed:@"Time Background.png"] forState:UIControlStateNormal];
[timerBackground setBackgroundImage:[UIImage imageNamed:@"Time Background.png"] forState:UIControlStateHighlighted];
[timerBackground addTarget:self action:@selector(openTimeChanger:) forControlEvents:UIControlEventTouchUpInside];
timerBackground.frame = CGRectMake(-2 , 15, 102, 27);
[timerView addSubview:timerBackground];



-(void)openTimeChanger {
    [UIView animateWithDuration:0.2f
                     animations:^{
                         changerBackground.frame = CGRectMake(-12 , -16, 105, 33);
                     }
                     completion:Nil];
}

还要注意 changerBackground 有 3 个子视图。

4

1 回答 1

1

你需要改变这个,

[timerBackground addTarget:self action:@selector(openTimeChanger:) forControlEvents:UIControlEventTouchUpInside];

[timerBackground addTarget:self action:@selector(openTimeChanger) forControlEvents:UIControlEventTouchUpInside]; //note that semicolon is not there in the method name

您的方法定义 is-(void)openTimeChanger和 not -(void)openTimeChanger:(id)sender。它试图找到具有此定义的方法,但该方法不可用,因此崩溃。

如果要使用[timerBackground addTarget:self action:@selector(openTimeChanger:) forControlEvents:UIControlEventTouchUpInside];,则将方法更改为-(void)openTimeChanger:(id)sender.

于 2012-11-27T01:59:09.007 回答