tjr
tjr

Reputation: 143

UIButton not showing highlight when selector action is to push a new UIViewController

I have an iPhone / iOS application in which there exist UIButtons (plain, with text labels; no custom graphics used) which, when pressed, push a new UIViewController onto the UINavigationController stack.

The buttons appear indirectly on a UIScrollView; they are all directly on another UIView, which is constructed at runtime, and then this UIView is added to the UIScrollView.

The problem: when a user presses one of these buttons, in most instances, the button does not show as highlighted, although the correct action is taken (the proper view controller is pushed onto the stack).

If I set the press detection to use TouchUpInside rather than TouchDown, then if the user holds the button pressed down for a short time (half a second, perhaps?) the button shows as highlighted, but using TouchDown it is rarely highlighted, and in any event, I would prefer that the highlight shows up even if the user just lightly taps the button.

I've researched this site and others for answers, and tried the various approaches that I found suggested for combating similar issues.. The most likely answer seemed to be setting the "delaysContentTouches" property to NO for the UIScrollView, but this made no discernable difference in my application. Indeed, nothing that I found satisfactorily answered the question.

Any ideas?...

Upvotes: 3

Views: 2531

Answers (1)

Costique
Costique

Reputation: 23722

Yes, the delay is caused by UIScrollView trying to detect a scrolling gesture, and yes, you can solve it by setting delaysContentTouches to NO. Moreover, you should always use UIControlEventTouchUpInside rather than UIControlEventTouchDown with UIButton because that allows the user to "change her mind" by dragging the finger farther away from the button.

Upvotes: 13

Related Questions