Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
778 views
in Technique[技术] by (71.8m points)

iphone - UIButton event 'Touch Up Inside' not working. 'Touch Down' works fine

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...