Tien Nguyen Tien Nguyen - 27 days ago 9
Swift Question

UITextView's not displaying content during push animation when is in inputAccessoryView

I have

UIViewController
that has
inputAccessoryView
overrided with custom
UITextView
, lets call that view controller A. And I have another view controller that push A to navigation stack.

So, when I push A first time everything is ok - the
UITextView
appeared with text immediately. The strange thing starts with next push - the
UITextView
's text does not appear until view controller push transition animation end.

During animation =>
Animation completed

The code of viewController A is there:

class NextViewController: UIViewController {

private var userInputView: UIView!

override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor.grayColor()

let textView = UITextView(frame: CGRect(origin: .zero,
size: CGSize(width: 200, height: 30)
), textContainer: nil)
textView.text = "asd"

userInputView = textView
}

override var inputAccessoryView: UIView? {
return userInputView
}

override func canBecomeFirstResponder() -> Bool {
return true
}

}


Tested in iOS 9.3 simulator.

After some coding I noticed that if
inputAccessoryView
is not deallocated (stored somewhere in global scope) the appearance during animation is defined by last
UITextView
state. But this solution is not good for me
is ok actually. But is there any native-like solution, am I missing something? Because the desired behaviour is rather standard in my opinion.

Answer

So I will stick with the solution where the inputAccessoryView is stored until next appearance.