Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Snapshotting a view (_UIReplicantView) that has not been rendered at least once requires afterScreenUpdates:YES

I'm a new programmer that's still learning, so forgive me if my code looks like crap. I'm writing a program that has a ViewController called "infoViewController" with multiple UITextFields on it. The user is supposed to fill out the textfields and then click the "Next" button in the upper-right of the screen, which then activates a "Show" segue and takes them to the next VC. All the info from the Text Fields are stored in constants for later down the road when I take that information that they inputted and place it on a .PDF file that is generated at the end. I wanted the user to be able to easily go through the text fields, so I made it where when the user is on the TextField and clicks "Next" on their keyboard, it moves them to the next TextField so that they can fill them all out quickly and easily. The issue I run into is that for some reason I keep getting this error when I click "Next" on the keyboard:

[Snapshotting] Snapshotting a view (0x7f89955786c0, _UIReplicantView) that has not been rendered at least once requires afterScreenUpdates:YES.

The app still works... but I'd rather not have an error showing up in the panel (in Xcode) at all lol. Also, when it does this, it's like the screen glitches and flickers white for a split second (super fast) before it moves on to the next TextField... any solutions?

Please dumb anything you reply down to a beginners level. Thanks!

Here's the code I wrote for switching between TextFields:

extension infoViewController {

func textFieldShouldReturn(_ textField: UITextField) -> Bool {
    let nextTag = textField.tag + 1

    if let nextResponder = textField.superview?.viewWithTag(nextTag) {
        nextResponder.becomeFirstResponder()
    } else {
        textField.resignFirstResponder()
    }

    return true
}

}

I assigned the TextField delegates in "viewDidLoad." (Ex: clientTextField.delegate = self)

I also assigned the tags in "viewDidLoad." (Ex: clientTextField.tag = 0)

like image 325
Christian W Avatar asked Mar 14 '20 19:03

Christian W


2 Answers

I had the same warning whenever a textField switched firstResponders. But this only happened for textFields that had the Text Input Trait of Capitalization set to anything other than None.

Text Input Traits can be found in the Attributes Inspector under Min Font Size.

In my case, changing Text Input Trait of Capitalization to None removed that warning. While this worked for me, I imagine this only solves a symptom, not the underlying problem.

like image 120
Mykol Avatar answered Oct 18 '22 22:10

Mykol


I would say, wrap your call to

 nextResponder.becomeFirstResponder()

And also your call to

 textField.resignFirstResponder

In a very brief delay to let the function return before you play with the first responder.

like image 31
matt Avatar answered Oct 18 '22 23:10

matt