开发者

UIButton firing selector inconsistantly

I have a UIButton linked up in IB correctly(I believe). The button fires inconsistently, every time I reload the view to show updated info, the button works sometimes and sometimes does not.It gives no errors. I can't find a pattern to when i开发者_开发知识库t works and when it doesn't, the same code is run every time I open the view and it still works when it wants. Besides linking it in IB I have also tried to addTarget in ViewDidLoad and remove the IB connection but it still has the same inconsistency,

[_buttonScreen addTarget:self action:@selector(buttonScreenClicked)  forControlEvents:UIControlEventTouchUpInside];   

If I add NSLog(@"Clicked"); to buttonScreenClicked I see that the method doesn't always get called, what would cause it to do this, I have made sure that I set:

[_buttonScreen setAlpha:0.1];
[_buttonScreen setHidden:NO];
[_buttonScreen setUserInteractionEnabled:YES];

I have no Image, text, or color in the button, but it still works sometimes. I'm using AFKPageFlipper on the same view but it still had the same problem before I added AFKPageFlipper, so I don't think its that.

If anyone could point me in any direction to start trouble shooting this problem I would appreciate.

Thanks


I just had the same problem and worked it out. The 5 seconds is the clue.

Somewhere you have a gesture recognizer covering the same space as your button. More specifically you have a gesture recognizer that is eating your Taps but not your LongPresses. If you just tap the button the gesture recognizer runs off with your event; Hold your finger down long enough and the gesture recognizer no longer considers it a tap and the event is passed through to your button.

Instrument your Tap gesture recognizer handlers and the problem should pop out at you.


Make sure you don't have any other UIView descendants overlaying the button (like a transparent UIScrollView) as these will intercept the touch events first.

Also make sure that the containing view (the view with the button in) is correctly sized, by default you can place a view outside the bounds of another view and the clipsToBounds is set to false so you will see it but not be able to interact with it.


Things to try:

Do you have any other actions on the button? Do you have any other UIViews which could possibly be accepting the key presses (above or below, or un-shown) Also, please check that you have only one UIViewController instance for this screen. Other issues may arrise because of that. What happens if you dont set the alpha level?

Do you release the object properly in the dealloc only ?

Hope this helps

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜