gpt4 book ai didi

ios - UITabBarController canBecomeFirstResponder 方法未被调用

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

看完http://nshipster.com/uikeycommand/我想在我的应用程序中使用箭头键在选项卡之间添加导航。但是我无法在 UITabBarController 中接收到按键。下面的相同代码块在 UIViewController 中工作,但在 UITabBarController 中工作。

当我尝试调试时,甚至没有调用 UITabBarController 的 canBecomeFirstResponder 覆盖。我没有在 apple 的文档中找到有用的东西。感谢任何使问题清晰的信息。

override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)

let firstResponderResult = self.becomeFirstResponder()
println("became first responder \(firstResponderResult)")
}

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

override var keyCommands: [AnyObject]? {
return [
UIKeyCommand(input: UIKeyInputRightArrow, modifierFlags: UIKeyModifierFlags.allZeros, action: "rightArrowClicked:"),
UIKeyCommand(input: UIKeyInputLeftArrow, modifierFlags: UIKeyModifierFlags.allZeros, action: "leftArrowClicked:")
]
}

func rightArrowClicked(sender: UIKeyCommand) {

let currentIndex = selectedIndex;

if (currentIndex < viewControllers!.count - 1) {
selectedIndex = currentIndex + 1;
}
}

func leftArrowClicked(sender: UIKeyCommand) {
let currentIndex = selectedIndex;

if (currentIndex > 0) {
selectedIndex = currentIndex - 1;
}
}

最佳答案

我认为您应该覆盖 UITabBarController 中 VC 的 canBecomeFirstResponder 方法,而不是选项卡栏 Controller 的方法。这样您应该能够获得按键。

关于ios - UITabBarController canBecomeFirstResponder 方法未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32405825/

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