1

我只是添加一个带有按钮的快速介绍屏幕,它可以正确编译和显示,但我的按钮没有响应。

- (void)viewDidLoad {
   [super viewDidLoad];
   NSLog(@"viewDidLoad!");
   [self showIntro];
}

//  make a quick Intro screen
- (void) showIntro {
   UIImageView *myBackImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
   [myBackImage setImage:(UIImage *) [UIImage imageNamed:@"myBkgnd.png"]];

   UIButton *clickBtn = [UIButton buttonWithType:UIButtonTypeCustom ];
   [clickBtn addTarget:self action:@selector(myButton_pressed:) forControlEvents:UIControlEventTouchUpInside];
   [clickBtn setImage:(UIImage *) [UIImage imageNamed:@"btnImage.png"] forState:UIControlStateNormal];
   clickBtn.frame = CGRectMake(111, 200, 75, 60);
   [myBackImage addSubview:clickBtn];
   [self.view addSubview:myBackImage];
}

- (void)myButton_pressed:(UIButton*)button {
   NSLog(@"Button Pressed!");
}

我在看什么?谢谢!

4

1 回答 1

3

正如您已添加UIButton但您没有UIImageView忘记imageView's userInteraction. default NO所以 :

myBackImage.userInteractionEnabled = YES;

编辑:刚刚格式化

于 2012-11-02T04:31:08.883 回答