切换视图控制器时,按钮操作不响应

时间:2013-08-20 18:47:13

标签: objective-c

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

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:没有响应。此代码在第一个viewcontroller中工作正常。

有什么问题?

0 个答案:

没有答案