gpt4 book ai didi

ios - 选项卡 View 的 3D 触摸快捷方式,然后执行 segue

转载 作者:行者123 更新时间:2023-11-29 01:15:04 24 4
gpt4 key购买 nike

我在应用程序中使用 3D 触摸快捷方式时遇到问题。我的应用程序使用选项卡,但我想将用户重定向到选项卡,然后在按下创建愿望列表按钮时也重定向到另一个 segue。

Here is a picture of my storyboard.

我现在使用的代码显示主视图 Controller ,但我希望它进入创建愿望列表 Controller 。

我在应用程序委托(delegate)内的句柄快捷方式的代码位于此处:

   func handleShortcut( shortcutItem:UIApplicationShortcutItem ) -> Bool {
print("Handling shortcut")

var succeeded = false

if( shortcutItem.type == "com.example.Giftr" ) {

print("- Handling \(shortcutItem.type)")

if let tabVC = self.window?.rootViewController as? UITabBarController{
tabVC.selectedIndex = 1
//This is where I need to swap to the "createwishlist" view controller.
}

最佳答案

为了解决这个问题,我使用了一个全局变量来存储快捷方式已在 appDelegate 中获取,如下所示。

          GlobalVars.shortcut = 1
let tabVC = window?.rootViewController as! UITabBarController
print(tabVC.self)
tabVC.selectedIndex = 0

然后在 selectedIndex 0 选项卡的 Controller 内部检查该值是否为 1,然后它是否被转到我想要结束的 View Controller 。如图所示。

override func viewDidAppear(animated: Bool) {    
if(GlobalVars.shortcut == 1)
{
self.performSegueWithIdentifier("shortcut", sender: self)
GlobalVars.shortcut = 0
}
}

确保将全局变量设置为 0,否则每次出现 View 时都会调用它。

关于ios - 选项卡 View 的 3D 触摸快捷方式,然后执行 segue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35282119/

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