1

I have a button and with a control Event like :

[_flashBackButton addTarget:self
                     action:@selector(flashBackButtonCallback:)
           forControlEvents:UIControlEventTouchUpInside];

if I use UIControlEventTouchUpInside there is a very small delay (1sec) before my selector is called (a delay after that I stopped touch the screen).

I have tried with

[_flashBackButton addTarget:self
                     action:@selector(flashBackButtonCallback:)
           forControlEvents:UIControlEventTouchDown];

my selector is called immediately.

=> the problem is that this button is use to display another view controller, and this long delay is making our app feel unresponsive. When I compare to other well known apps such as facebook, twitter etc, their view controllers are poping almost right after the button is pressed.

Does someone who knows a way to fix it? I don't want to use UIControlEventTouchDown.

thanks in advance for your help

to see a video : https://www.dropbox.com/s/kl1sr5jnpzo1i7s/IMG_2865.MOV

amau96
  • 857
  • 1
  • 8
  • 19
  • How long is the delay and what problem does it cause? – Wain Apr 23 '13 at 12:22
  • the delay is about 1 sec. => the problem is that this button is use to display another view controller, and this long delay is making our app feel unresponsive. When I compare to other well known apps such as facebook, twitter etc, their view controllers are poping almost right after the button is pressed. – amau96 Apr 23 '13 at 12:27
  • Then this has nothing to do with what control event you are using, can we see the code you execute when the button is tapped? It sounds like you're blocking the UI thread momentarily causing the delay before the view controller is presented. – Mick MacCallum Apr 23 '13 at 12:31
  • In the iOS Simulator or on a device? Do you have other views below/above your button that capture touch input? `UIControlEventTouchDown` DOES have a delay, but it's only about 50-100ms in the iOS Simulator... – Andreas Ley Apr 23 '13 at 12:31
  • 1
    are you adding the button to scrollview or to the self view – Anand Apr 23 '13 at 12:32
  • Look at doing some profiling / logging in your app as a 1 second delay is abnormal. What is the app doing when the button is on display? Does the button highlight (and remove highlight) when your finger is touched down and then moved away from the button without being released? – Wain Apr 23 '13 at 12:32
  • Like I said, if I use :[_flashBackButton addTarget:self action:@selector(flashBackButtonCallback:) forControlEvents:UIControlEventTouchDown]; the other view controler is showing immediately – amau96 Apr 23 '13 at 12:36
  • are you adding the button to scrollview or to the self view => the button is a simple UIBarButtonItem placed inside the navigationbar of my main view controller – amau96 Apr 23 '13 at 12:55
  • 1
    The problem IS in your code, because `PPRevealSideController` works fine. Also, a `UIBarButtonItem` doesn't have a `addTarget:action:forControlEvents:` selector. We really need to see more of your code to be able to help you. – Andreas Ley Apr 25 '13 at 07:31

2 Answers2

1

It sounds like you have something in the next viewController's viewWillAppear method blocking the main UI thread. Place an NSLog on the source viewController;s action and see if it fires immediately then place another on the destination viewWillAppear method. That should narrow down the issue.

Mark McCorkle
  • 9,349
  • 2
  • 32
  • 42
  • Like I said, if I use :[_flashBackButton addTarget:self action:@selector(flashBackButtonCallback:) forControlEvents:UIControlEventTouchDown]; the other view controler is showing immediately – amau96 Apr 23 '13 at 12:46
  • Are you using a scrollview as others have asked? – Mark McCorkle Apr 23 '13 at 12:47
  • For the side view, I am using : https://github.com/ipup/PPRevealSideViewController – amau96 Apr 23 '13 at 13:02
  • Ok, take away that variable and just create a new UIViewController and see if that fixes the issue. I have to assume it's that destination controller causing the issue. But if you have already used the NSLog as I have suggested then you should already be seeing where the delay is. – Mark McCorkle Apr 23 '13 at 13:03
  • No, as the splitViewController are use exclusively on iPad device – amau96 Apr 23 '13 at 13:06
  • 1
    The problem is probably not with the actual event. That's why I keep repeating myself saying to place an NSLog into the action as well as the destination controller. Also, remove the other variable by pushing on a fresh viewController. Your delay more than likely has nothing to do with the touchDown event. If the NSLog fires immediately after pressing the touchDown then you know where the problem lyes. Also, USE BREAKPOINTS. They narrow these things down in 1 second. – Mark McCorkle Apr 23 '13 at 13:20
  • If I only put log in my selector, I have the same delay in my console -(IBAction)flashBackButtonCallback:(id)sender { NIDPRINT(@"flashBackButtonCallback - begin"); } if I use :[_flashBackButton addTarget:self action:@selector(flashBackButtonCallback:) forControlEvents:UIControlEventTouchDown]; the log is showing immediately So it can't be a problem with my view controller as I don't call a viewController anymore. The only difference is UIControlEventTouchDown instead of UIControlEventTouchUpInside – amau96 Apr 24 '13 at 06:25
1

Ok, I have figure out what the probleme was :
my button is an uiBarButtonItem and I have a gesture recognizer (double tap) on my uinavigation bar.
This was this gesture that cause the latency. I have fix my probleme with :
Click events in UINavigationBar overridden by the gesture recognizer

Community
  • 1
  • 1
amau96
  • 857
  • 1
  • 8
  • 19