ios - How to switch custom in-app keyboards -


recently i learned make custom in-app keyboards. want able swap between multiple custom keyboards. however, resetting textfield.inputview property not seem work.

i recreated simplified version of problem in following project. uiviews represent actual custom keyboards.

import uikit class viewcontroller: uiviewcontroller {      @iboutlet weak var textfield: uitextfield!      override func viewdidload() {         super.viewdidload()          let blueinputview = uiview(frame: cgrect(x: 0, y: 0, width: 0, height: 300))         blueinputview.backgroundcolor = uicolor.bluecolor()          textfield.inputview = blueinputview         textfield.becomefirstresponder()       }      @ibaction func changeinputviewbuttontapped(sender: uibutton) {          let yellowinputview = uiview(frame: cgrect(x: 0, y: 0, width: 0, height: 300))         yellowinputview.backgroundcolor = uicolor.yellowcolor()          // doesn't cause view switch         textfield.inputview = yellowinputview      } } 

running gives expect: blue input view pops up.

enter image description here

but when tap button switch yellow input view, nothing happens. why? need work?

after little more experimenting have solution now. needed resign first responder , set again. first responder subview of top view can resigned indirectly calling endediting.

@ibaction func changeinputviewbuttontapped(sender: uibutton) {      let yellowinputview = uiview(frame: cgrect(x: 0, y: 0, width: 0, height: 300))     yellowinputview.backgroundcolor = uicolor.yellowcolor()      // first     self.view.endediting(true)     // or     //textfield.resignfirstresponder()      textfield.inputview = yellowinputview     textfield.becomefirstresponder() } 

thanks this , this answer ideas.


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -