UIButton firing selector inconsistantly - objective-c

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 it 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

Related

UIbutton not responding to touch

I have this view hierarchy:
The three buttons don't response. They are enabled, just when I touch there, they don't do anything (not even change their gradient/tint) which tells me they are not even received the touches. Is there something I am doing wrong?
Thanks
User interaction is enabled on all the buttons' superviews, and the buttons themselves. The buttons are also enabled.
Are you using any imageViews on top or containing the UIButtons? If so, sometimes, those absorb the touches because they have the userInteraction boolean set to NO by default. Maybe even getting rid of your gradient imageView (for the time being) to determine if those are causing the issues.
If not, I would set a breakpoint on the viewDidLoad method of the superview and type in [self.view recursiveDescription]. It should give you at-a-glance overview of what's around those buttons and might be stealing the touches.
Good luck!

Subview of Scrollview doesn't register touch events

I'm struggling with this problem, and although there are quite some threads on this issue I've not figured it out yet.
I want to load a button into a subview of a scrollview. If I test this subview alone, the button works fine. Also, when I add the button to the scrollview directly, it works fine. But the two combined I don't get any touch event on the button.
My view hierarchy:
UIScrollView
UIView
UIButton (A)
UIButton (B)
So button B works fine, A doesn't.
I've tried messing around with the attributes like Cancellable Content Touches, but so far no luck. I'm loading the subview from the storyboard with:
ViewVC *viewVC = [self.storyboard instantiateViewControllerWithIdentifier:#"ViewVC"];
From the posts I've read, this should just work, so either I'm missing something vital, or I've messed up some attributes along the way. Should I use a delegate to pass the events, or should this be done automatically?
Give your views some colours, and check if one of them is obscuring the other preventing it from being touched. Maybe you UIView is overlapping your UIButton(B), preventing it from being touched.
How are you sure you're adding it?
Make sure you're calling addSubview: on your UIScrollView with your subview as the parameter?

UIPopoverController takes control and won't let go

I have a few Popovers that I present from UIBarButtonItems.
The popovers are Property settings for an Object, Color, Size, Positioning, name, line thickness, etc.
As the settings in the popover change, the Object they are properties for also changes in realtime.
Most of the time a tap away from the popover clears it. Though sometimes something happens to the environment where the responder chain seems to be broken and a tap away from the popover no longer dismisses the popover. The Property controls in the popover still work, though there is no way to dismiss the popover.
On Popovers with TextFields, I can alter the text, dismiss the Keyboard and then I can Dismiss the popover normally.
Any Tips on where to start Logging and see who's on top of the responder chain and who's able to receive gestures/touches.
Thanks!
When I was debugging recognizers and such (similar), I put a UITapGestureRecognizer on the main background view, calling a method viewTapped:. In viewTapped: you can dismiss any outstanding popovers (handy if they are properties of the VC). You can also send resignFirstResponder if you worry about any textFields that might not be cooperating.
Are you setting any passthrough views? You might examine those. Normally you don't have any ability to tap outside the popover without dismissing unless you specifically set the passthroughViews.
Good luck,
Damien

iOS 5 WeeApp Widgets not responding to touches

I have the problem that in Notification Center widgets touch events are not being registered. Lets say, i have a simple widget with a view (_view) and a UIButton with target:self forEvent:touchDown. If I then press the button on my device nothing happens. I need to hold it for a short period of time, then the "touch" (more like hold) gets recognized and the action for the button starts. I've seen widgets where touch events work fine (UISettings, SBSettings 5), what do I need to modify in order to behave like a "normal" UIView?
I ended up figuring it out myself. I just added a UITapGestureRecognizer to the UIButton. The selector for the Gesture gets called immediately when the screen is touched, and doesn't have the annoying "delay" effect like the UI Objects. I have used it with three UIObjects so far: UIButton UIBarButtonItem and UISegmentedControl. For the segmented control simply detect the x-coordinate of the touch and then select the relevant segment. It should also work with UISlider UISwitch etc. . The only object that isn't working for me is UITextField. The clear button on that isn't responding to the clear selector so i wanted to add a gesture for that, without success.

UIButton on UIButton

Here is a question for you:
I've got a UIButton that we'll call bottomButton. I have another UIButton that we'll call topButton. What I want to do is place topButton on top of bottomButton such that when you tap topButton, it's action is executed. The problem that I'm having is that when I tap topButton, its bottomButton's action that is getting executed.
So what I want to know is if it is possible to place a UIButton on another UIButton so that when tapped, only the top UIButton registers the tap. Savvy?
Any input is appreciated!
Yes, it's possible. There are three things to check out:
1) Is topButton actually situated above bottomButton in the view stack? [UIView bringSubviewToFront:] may help here.
2) Is topButton large enough to register the tap? Try making topButton larger than 44x44 and see if that helps.
3) Make sure that topButton is enabled.
EDIT
I just saw your comment about adding topButton as a subview of bottomButton, and that's likely to be part of the problem. You could try adding both bottomButton and topButton to a new UIView, and then add that new UIView where you had previously used bottomButton.
If top button is a subview of bottom it won't get the touch events passed to it because the bottom button's hitTest:withEvent: is called first and it will return YES.
You could try overriding hitTest:withEvent: for the bottom buttom to have it call hitTest on its subviews (normally it doesn't have UIControls in its subviews) and return that subview instead if it has a hit.
Ah, I see now from reading your comments. Since you're adding a button TO another button, you'll need to make the superview intercept the touch event.
Read this post:
How to make a superview intercept button touch events?
I'm not sure about this one but have you tried adding them to the view in different orders? Does that make a difference? Test it out and see what happens!
Why would you add a button to a button?
Try adding them to the same parent but putting topButton over bottomButton.