11
votes

I've got a UIButton in a UIView, which is in a UIViewController that I've allocated and inited from a .xib file.

When hooking an IBAction up to the 'Touch Down' event of a UIButton it triggers correctly. But if I hook it up to the 'Touch Up Inside' event it doesn't respond.

Other events don't work either. 'Touch Drag Enter', 'Touch Drag Exit', 'Touch Up Outside' etc. Only Touch Down.

Does anyone have any idea why this might be?


The button is a simple rounded rectangle button in a view controller. I have loaded the view controller as such:

-(void) pushNewViewController
{
    MyViewController* newViewController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
    [self.view addSubview:newViewController.view];
    [newViewController release];
}

I've added this button to rounded rect button to MyViewController, in IB. I created the following IBActions:

-(IBAction) buttonTouchDown:(id)sender
{
    NSLog(@"Button Touch Down Event Fired.");
}

-(IBAction) buttonTouchUpInside:(id)sender
{
    NSLog(@"Button Touch Up Inside Event Fired.");
}

In the IB I menu clicked on the button and dragged the Touch Down outlet to MyViewController and selected buttonTouchDown:. Saved the IB xib.

When I run and test the button and get the "Button Touch Down Event Fired" log message.

But when I go back to IB and change the Action to Touch Up Inside and hook it upto the buttonTouchUpInside: IBAction and save. I test again, I get no response.

Regards, Rich

5
Is that question still open? It originates from October, did you find a solution meanwhile?Axel

5 Answers

20
votes

I'm sorry for being late but I have exactly the same problem. In my case it was a UITapGestureRecognizer assigned to parent view. So, it's good idea to check for recognizers as well.

6
votes

You're releasing newViewController.

While the adding the newViewController.view as a subview will retain the view, the newViewController object will have a retain count of 0.

2
votes

You mentioned saving; did you save both the xib and your MyViewController files after you made your changes? Often when something like this stops working for me, I find that I didn't save either the xib in IB or the class file in XCode.

2
votes

Do you have any touch-event handlers implemented in your MyViewController's code?

It looks like your UIButton only receives touchesBegan event and the event gets cancelled by something before it could receive touchesEnded.

Something like UIScrollView usually does when it's deciding between touch that needs to be forwarded to it's subviews and a drag that should be handled by itself.

0
votes

Lol well this was dumb solution, but in the xib I had it linked to buttonTouchUp outside, and that was causing the problem. Maybe this will help :)