0

我有一个应用程序,如果按下按钮,就会切换视图控制器。我这样切换:

NewViewController *nv = [[NewViewController alloc] init];
[nv NewButtonTapped:self];
[self.view addSubview:nv.view];

然后在我的 NewViewController.m 中:

- (void)NewButtonTapped:(id)sender
{
backgroundImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 1024, 748)];
backgroundImage.image = [UIImage imageNamed:@"cubePage.png"];
[self.view addSubview:backgroundImage];

button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(964, 100, 60, 150);
button.enabled = YES;
button.userInteractionEnabled = YES;
[button setTitle:@"D" forState:UIControlStateNormal];
button.backgroundColor = [UIColor blueColor];
[button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}

- (void)buttonTapped:(id)sender
{
NSLog(@"Tapped");
}

所有图像和按钮都已加载并且在新的视图控制器中显示良好,但是buttonTapped:当我点击按钮时按钮操作没有响应。此代码在第一个视图控制器中运行良好。

有什么问题?

4

0 回答 0