0

I'm trying to add UIToolbar to my keyboard with inputAccessoryView, but once the user tap the UITextField I get an Blank white screen or load White view if i put it in viewDidLoad(). I have tried few stackoverflow QA and non of them seems to be working for me. I'm also doing this with removeFromSuperview() method.

Initialization:

@IBOutlet var MessegeView: UIToolbar!
@IBOutlet var MessegeTextField: UITextField!

Assign UIToolbar to UITextField: This code result in blank white view when it get loaded.

override func viewDidLoad() {
     super.viewDidLoad()
     MessegeTextField.inputAccessoryView = MessegeView
     MessegeView.removeFromSuperview()    
}

WITHOUT removeFromSuperView(): I get the following error and that make sense kind of.

ERROR: 

should have parent view controller:<APPNAME.ChatViewController:XXXXXXXX> but requested parent is:<UIInputWindowController: XXXXXXXXXX>

A few Stackoverflow QA I follow (but no result):

How views are setup:
enter image description here

Community
  • 1
  • 1
Brian Nezhad
  • 6,148
  • 9
  • 44
  • 69

1 Answers1

0

If you setup your UI in a Storyboard then you don't own the objects and shouldn't alter the hierarchy. That's why Xcode auto-generated properties from storyboards are @IBOutlet weak var by default, you don't own them and shouldn't manage the memory.

To fix your problem you should either use var MessegeView = UIToolbar() or you should initialize the toolbar from a separate .xib.

InkGolem
  • 2,662
  • 1
  • 15
  • 22