Delay after prepareForSegue before UIStoryboardSegue/View shows up - ios

I have a simple iOS application written in Swift that is hanging every 2nd time I tap a row to present the next view.
The first time, 3rd, 5th, etc times I select a row it waits for 5-15 seconds and then a modal MZFormSheetPresentationController (or whatever modal view) is shown.
If I dismiss and tap the row again (to show the same modal) it appears immediately. If I'm in the delay sequence and I tap somewhere else it triggers the appearance immediately. That made me feel like a main thread issue, but I can't find anywhere I get off track.
I found prepareForSegue was missing a super call, but adding it, or commenting entirely has no bearing. Happens regardless of if the Segue kind is Modal or Custom; if it has a custom class or not, if animates is enabled
Sometimes it feels like taps are being dropped entirely (The dismiss button feels especially random).

Related

Tapping screen causes current controller to return to previous controller [duplicate]

This question already has an answer here:
Swift 4 Odd unexpected jump back to earlier storyboard
(1 answer)
Closed 4 years ago.
Every time I tap somewhere along the top part of a view controller, it would return to the previous view. Root Controller is not affected as it doesn't have anything to return too. All of my View Controllers are affected though. (Please read update 3)
Things I've tried:
Looked for unnecessary gesture recognizer. (Result: I received nil when I check for the list gestures.)
I figured I might have accidentally added or left a IBOutlet to the view or something. (Result: There was no unnecessary IBOutlets.)
I disabled user interaction from a view to see if it would be affected. (Result: The bug seemed to go away until I enabled user interaction again.)
I've tried to do some research but I wasn't getting the results I wanted.
Tapping above the green line will make the View Controller return to the previous Controller.
I'm still relatively new to Objective-C and Xcode so I don't know if I'm making a rookie mistake or not.
UPDATE (Please read update 3)
Still nothing but here are a few more things i've tried:
Logging every user action.
Created a new project with new view controllers.
Opened a previous project to test it's view controllers.
Uninstalled and reinstalled Xcode.
All attempts still came with that weird bug.
UPDATE 2(Please read update 3)
I've decided to put a band-aid over the problem. Since the bug doesn't work when clicking over a button, I put constraints on a empty button, put it on top of the background image and removed the effect when button is tapped.
I thought this would work but there is a few spots on the screen that activates the bug. I experimented and figured that certain parts of ui elements activated the bug. (Example: Some labels in a Stackview, top part of a textfield, a switch, top part of a UICollectionView, etc.)
I've disabled user interaction for certain ui elements. Unfortunately not all ui elements could be disabled because some require user interaction.
Also I figure out that tapping with three fingers on the screen somehow activates the bug.
Here is an error code I received in the console when I was trying multiple taps on the screen:
<_UISystemGestureGateGestureRecognizer: 0x2822fc1e0>: Gesture: Failed to receive system gesture state notification before next touch
UPDATE 3
After playing around with the code again. I believe I've figured out what is causing the problem but not how to fix it.
I believe it has to do with the story board segue, or at least the transitions being used. If I set the kind to "Show(e.g. Push)" than it works fine, but if I set the kind to "Present Modally" and the transition to "Partial Curl", the bug does it's thing.
Sidenote: This is how I tested it. I created a new project (I don't think the language matters). The project has two view controllers; one button each with segue pointing at each view controllers. Segue 1 has it's kind as "Present Modally" and the transition as "Partial curl". Segue 2 is on the 2nd view controller and has it's kind as "Show(e.g. Push)". To test the bug, tap along the top part of the screen. If the bug worked, then it should show the partial curl transition but in reverse and send the user back to the 1st view controller.
maybe you are experiencing the standard swipe back gesture coming from the navigation controller. It thats the case try this code:
Objective-C:
if ([self.navigationController respondsToSelector:#selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}
Swift:
navigationController?.interactivePopGestureRecognizer?.isEnabled = false

IOS: first tap not working just after loading view

I have noted recently that each of my app view has one particular bug/behaviour: if user taps too fast on a UI component when the view appears, the tap is simply ignored. If the user wait a bit before tapping, the tap works.
Storyboard is used for the storyboard, tap gesture recognisers are on UIImageview and using IOS 10.2.
Through different forums i have read about the following options:
nest the call of "present view controllers" in main thread
Call CFRunLoopWakeup before presentviewcontroller
Add programatically the TapGesturerecognizer
change the states of "delays touches end" and "delays touches began"
disable 3d touch option as similar symptoms was reported to happen in other apps
All above have been unsuccessful.
Anyone would have met similar issues with the first tap just after the view load?
[Update: I realise this misbehaviour is not specific to this app. Two tests to try:
create an xCode Project for iPhone and two view controllers Controller A and Controller B. Two buttons : a button on Controller A view to go to Controller B view and a button Back in Controller B view to go back to Controller A view. Tap to go from View A to B, tap back in B and try immediately to tap on button to go to B. First tap doesn't work either.
Go in Settings of the iPhone. Tap On Notifications. Press On Settings to go back to Main Settings screen, Tap immediately back on Notifications. If fast enough, first tap doesn't work. Second tap works or waiting a bit before first tap.
Question is now: this looks like a common problem across iPhone apps. Would you know if there would be a common setting somewhere? or is this a common bug for given IOS version ?
]
Stephane
This is a general problem (the moment when the view controller is changed, the first tap will be ignored), but this is not a bug that will happen only because the switch view controller's animation has not yet been completed. If you set the animation to false , then the view controller can immediately respond to your click, no matter how fast (anyway faster than your hand) :)

Where to implement auto-save code when using iOS 7 backwards edge swipe?

iOS 7 introduces edge swiping to navigate backwards in a navigation controller (so long as you don't override the leftBarButtonItem, among other things).
Imagine I'm implementing an app similar to Apple Notes. In Apple's app, once the user taps into a note, there is a Back button on the top left, and a Done button on the top right. This view controller is automatically saved after the user navigates away. Even if the user swipes backwards while still editing the note, it will auto-save.
One way to implement this is to write to disk on each key stroke. However, I'm looking for a more efficient implementation.
Which method should I override to perform my auto-save?
To be clear, the auto-save code should be invoked in these three cases:
The user taps the Back button
The user swipes backwards
The user taps the Done button
So far, I've been implementing the save logic in viewWillDisappear, this minimizes the amounts of writes, and also takes care to save if the user kills the app.
Additionally, instead of implementing save logic in the Done button, the Done button can simply call:
[self.navigationController popViewControllerAnimated:YES];
... (e.g. via a delegate, or unwind segue) and it will automatically save as well. All three code paths will go through viewWillDisappear.
Although it could technically be implemented in viewDidDisappear, if the previous view controller needs to display the updated data, this method will be too late.
For more complex view controllers (e.g. those that have destructive behavior once the view controller is dismissed), there are several other things to consider:
Should the save be called if a modal is presented above the current view controller? (e.g. In Apple Notes, imagine that the share button launched a modal; should it save when you tap on this button?). If it is important not to save at this time, you can read the value of presentedViewController. If it has a value, that means viewWillDisappear is being called because a modal is being presented above it.
Should the save be called if a view controller is pushed on to the current navigation stack? (e.g. Again, in Apple Notes, if the share button used a push instead of a modal, should it save?) You can check the value of isMovingFromParentViewController in this case.
If the user taps the home button to quit your app, should it save?
If the user begins swiping backwards then cancels the swipe to stay on the current screen, should it save?
Imagine the view controller is in a modal, when the modal is dismissed should the destructive action happen? Check isBeingDismissed in this case.
Same as above, but imagine the view controller is the second page in a navigation controller than is being presented.

iOS: View with datepicker and immediately keyboard visible very slow through segue

I have a view with a UIDatePicker (inserted in storyboard) and in which in the viewDidLoad instantly a textfield gets first responder status so the keyboard is visible.
This view loads quite slow (about 2 seconds the first time, 1 second thereafter). I've checked my app in the time profiler and nothing special visible. Just some peaks (as expected) during the segue, however none of my methods or code is responsible for that. After I've removed the UIDatePicker and the immediately visible keyboard it was a lot faster. But I need them both..any advice how to that? Can I preload this datepicker and the keyboard somehow and just reuse them?

UITextFields intermittently not allowing user interaction

I know it's a very long shot and the problem description is vague at best, but I'm hoping someone might have encountered that as well.
I have a UIViewController subclass that is being presented modally. The view of the controller contains some UIButtons and some UITextFields. The view controller might be presented multiple times during a user session; it is created every time it's presented and gets destroyed when it's dismissed. Most of the time everything works as expected, however, sometimes the text fields don't respond to user touch, i.e. tapping them does not bring up the keyboard. The buttons on the view work fine, it's just the text fields that become disabled.
What could possibly be causing this?
Turns out the reason UITextFields inside a modally presented view controller were not responding was that one of the long-living view controllers in the app called [self becomeFirstResponder] on itself, but never called [self resignFirstResponder]. It had to be the first responder in order for it to receive remote controls events when the app was playing music.

Resources