1

我有以下代码:

UIImage *registerImg = [UIImage imageNamed:@"register_button_normal"];
CGFloat registerOffsetX = (view.frame.size.width - registerImg.size.width) / 2;

UIButton *registerBtnTwo = [[UIButton alloc] init];
registerBtnTwo.frame = CGRectMake(registerOffsetX, 111, registerImg.size.width, registerImg.size.height);

[registerBtnTwo setBackgroundImage:registerImg forState:UIControlStateNormal];
[registerBtnTwo addTarget:self action:@selector(submitRegister) forControlEvents:UIControlEventTouchUpInside];
[registerPanel addSubview:registerBtnTwo];
[registerBtnTwo release];

- (void)submitRegister;在类标题中作为实例方法;

问题是没有触发事件,因为我的 submitRegister 实现中有 NSLog

我试过的:

1. UIButton *registerBtnTwo = [UIButton buttonWithType:UIButtonTypeCustom];

2. UIButton *registerBtnTwo = [[UIButton alloc] initWithFrame:frame];

编辑 1:我将当前视图控制器添加到我的 navigationController 中的是谁?

if ( row == kLoginRegisterIndex ) {
    login = [[LoginRegisterVC alloc] init];
    [self.navigationController pushViewController:login animated:YES];
}  

编辑2:

UIView *registerPanel = [[UIView alloc] initWithFrame:frame];
registerPanel.backgroundColor = [UIColor colorWithPatternImage:image];

有任何想法吗?

4

2 回答 2

1

尝试改变

[registerBtnTwo addTarget:self action:@selector(submitRegister) forControlEvents:UIControlEventTouchUpInside];

[registerBtnTwo addTarget:self action:@selector(submitRegister:) forControlEvents:UIControlEventTouchUpInside];

方法签名是submitRegister:(不是submitRegister)。您不需要在标头中声明该方法。

如果这无助于检查主机视图的框架。当按钮在框架之外时,它可以显示,但不接受触摸。

我不明白您在编辑中要问什么。

于 2012-07-27T11:15:01.233 回答
0

问题是父视图是 UIImageView ,默认情况下 userInteractionEnabled = NO;

于 2012-11-16T08:48:17.053 回答