h4cky
h4cky

Reputation: 894

UIButton didn't call to target method

I have the following code:

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];

I have - (void)submitRegister; in class headers as instance method;

The problem is event isn't fired because i have NSLog in my submitRegister implementation

What i've tried:

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

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

EDIT 1: Who i add the current View Controller to my navigationController ?

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

EDIT 2:

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

Any ideas?

Upvotes: 1

Views: 153

Answers (2)

h4cky
h4cky

Reputation: 894

The problem was that parent view was UIImageView which by default have userInteractionEnabled = NO;

Upvotes: 0

dasdom
dasdom

Reputation: 14063

Try to change the

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

to

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

The method signature is submitRegister: (not submitRegister). You don't need to declare the method in the header.

If this doesn't help check the frame of the host view. When the button is outside of the frame it can be shown but it won't accept touches.

I don't understand what you are asking in your edit.

Upvotes: 1

Related Questions