【问题标题】:iOS App/Keyboard Plugin InvalidatediOS 应用程序/键盘插件无效
【发布时间】:2016-12-18 01:05:45
【问题描述】:

所以我一直在承担学习 Swift 和 XCode 界面以进入 iOS 开发的任务。为此,我一直在练习一些项目,这些项目可以帮助我了解这一切,所以我选择了一个制作自定义键盘的项目。但是,由于我猜这些教程是用旧版本的 Swift/XCode 编写的,所以我不断收到错误,尤其是一个。

每当我进入设置并添加我的自定义键盘时,我都会去使用它,每当我在键盘切换器中切换它时,键盘就会崩溃并默认恢复为原始 iOS 键盘(模拟器和我的手机都会发生这种情况.另外,目标iOS是正确的)。在那次崩溃后,我收到了这个错误:

plugin CalculatorKeyboard plugin myName.CalculatorKeyboard.Calculator interrupted
plugin CalculatorKeyboard plugin myName.CalculatorKeyboard.Calculator invalidated

我正在使用的当前代码:

class KeyboardViewController: UIInputViewController {

var customInterface: UIView!

override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
    super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)

    let nib = UINib(nibName: "Calculator", bundle: nil)
    let objects = nib.instantiateWithOwner(self, options: nil)
    customInterface = objects[0] as! UIView
    }

override func viewDidLoad() {
    super.viewDidLoad()
    view.addSubview(customInterface)
    }
}

旧代码:

// var customInterface: UIView!

    override func viewDidLoad() {
    super.viewDidLoad()
    loadInterface()
}

func loadInterface() {
    let calculatorNib = UINib(nibName: "Calculator", bundle: nil)
    let objects = calculatorNib.instantiateWithOwner(self, options: nil)
    view = objects[0] as! UIView
}

我希望我能在这方面得到一些帮助,因为我无法在 Google 上找到任何答案。谢谢! :)

注意:如果我可以使用旧代码,我会更喜欢,因为它在自己的功能中更简洁。

【问题讨论】:

    标签: ios swift xcode keyboard


    【解决方案1】:

    这会起作用

    override func viewDidLoad() {
            super.viewDidLoad()
            let nib = UINib(nibName: "KeyboardView", bundle: nil)
            let objects = nib.instantiateWithOwner(self, options: nil)
            view = objects[0] as! UIView;
    
        }
    

    还有一个很好的演示应用程序,它是用 swift 和 Objective-C 编写的 https://github.com/iManiaq/ios-color-keyboard

    编辑 转到设置->常规->键盘 在那里你添加你的键盘

    在此处输入图片说明

    【讨论】:

    • 我一回到家就试试这个并回复你。
    • 虽然我的键盘仍然没有弹出,但是我的错误已经解决了,所以这将是我必须研究的另一个问题。我给你的链接看看。谢谢!
    • 你必须手动添加你的键盘,去设置->通用->键盘那里你添加你的键盘我已经编辑了答案来解释相同请参考上面的答案了解更多详情
    • 我已经知道了,但是在我添加它之后,如果我点击,在这种情况下,“彩色键盘”,自定义键盘会闪烁并默认返回英语(美国) .
    猜你喜欢
    • 1970-01-01
    • 2018-06-09
    • 2016-07-02
    • 1970-01-01
    • 1970-01-01
    • 2018-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多