gpt4 book ai didi

ios - 黄色警告 : Conditional cast from UITextDocumentProxy to UIKeyInput always succeeds

转载 作者:搜寻专家 更新时间:2023-10-31 22:49:49 25 4
gpt4 key购买 nike

我正在使用键盘,我刚刚安装了 xcode 7 beta 2然后我收到很多警告。

超过 24 个黄色错误我认为这会使键盘崩溃on xcode 6.4 无错误无键盘当然

我发现很难解决这些错误。

警告:

Conditional cast from UITextDocumentProxy to UIKeyInput always succeeds

func handleBtnPress(sender: UIButton) {
if let kbd = self.keyboard {
if let textDocumentProxy = kbd.textDocumentProxy as? UIKeyInput {
textDocumentProxy.insertText(sender.titleLabel!.text!)
}

kbd.hideLongPress()

if kbd.shiftState == ShiftState.Enabled {
kbd.shiftState = ShiftState.Disabled
}

kbd.setCapsIfNeeded()
}
}

警告:

Conditional cast from UITouch to UITouch always succeeds

override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
for obj in touches {
if let touch = obj as? UITouch {
let view = self.touchToView[touch]

let touchPosition = touch.locationInView(self)

if self.bounds.contains(touchPosition) {
self.handleControl(view, controlEvent: .TouchUpInside)
}
else {
self.handleControl(view, controlEvent: .TouchCancel)
}

self.touchToView[touch] = nil
}
}
}

最佳答案

这些不是错误,它们只是警告,它们可能不是导致崩溃的原因,但是您可以通过执行以下操作来解决这两个示例:

无论如何,UITextDocumentProxy 协议(protocol)都符合 UIKeyInput,因此无需将 kbd.textDocumentProxy 转换为 UIKeyInput .

您将能够在没有任何警告的情况下执行以下操作:

func handleBtnPress(sender: UIButton) {
if let kbd = self.keyboard {
kbd.textDocumentProxy.insertText(sender.titleLabel!.text!)
kbd.hideLongPress()

if kbd.shiftState == ShiftState.Enabled {
kbd.shiftState = ShiftState.Disabled
}

kbd.setCapsIfNeeded()
}
}

obj一样,编译器已经知道它是一个UITouch对象,所以不需要强制转换,你可以把所有的代码都从中取出来>如果让 touch = obj 作为? UITouch 声明如下:

override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
for touch in touches {
let view = self.touchToView[touch]

let touchPosition = touch.locationInView(self)

if self.bounds.contains(touchPosition) {
self.handleControl(view, controlEvent: .TouchUpInside)
}
else {
self.handleControl(view, controlEvent: .TouchCancel)
}

self.touchToView[touch] = nil
}
}

小提示:alt 点击一个变量来查看它被解析为什么类型:

enter image description here

关于ios - 黄色警告 : Conditional cast from UITextDocumentProxy to UIKeyInput always succeeds,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31262500/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com