Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/118.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 通过NavigationController选项卡BarController NavigationController以编程方式导航_Ios_Swift_Uitabbarcontroller_Programmatically - Fatal编程技术网

Ios 通过NavigationController选项卡BarController NavigationController以编程方式导航

Ios 通过NavigationController选项卡BarController NavigationController以编程方式导航,ios,swift,uitabbarcontroller,programmatically,Ios,Swift,Uitabbarcontroller,Programmatically,我的故事板应用程序具有以下结构: NavigationController(NavCa)->CollectionViewController(VCa)->当前模式->TabBarController(TabBarC) TabBarC有两个选项卡,每个选项卡嵌入到自己的NavigationController中: 选项卡栏[0]导航控制器(NavCTab0)->表格视图控制器(VC01)->视图控制器(VC02)->视图控制器(VC03) 选项卡栏[1]导航控制器(NavCTab1)->视图控制器

我的故事板应用程序具有以下结构:

NavigationController(NavCa)->CollectionViewController(VCa)->当前模式->TabBarController(TabBarC)

TabBarC有两个选项卡,每个选项卡嵌入到自己的NavigationController中:

选项卡栏[0]导航控制器(NavCTab0)->表格视图控制器(VC01)->视图控制器(VC02)->视图控制器(VC03)

选项卡栏[1]导航控制器(NavCTab1)->视图控制器(VC11)->视图控制器(VC12)

我的问题:我的一个3D QuickAction必须直接导航到VC01

我确实检查过这个网站。这个话题和我的很接近。我尝试了代码(AppDelegate.swift中的快速操作处理程序):

但什么也没发生。输出窗口中没有显示任何内容。应用程序中未发生任何事件(如果应用程序被终止,它将启动VCa屏幕;如果应用程序未终止,它将停留在快速操作之前的位置)

非常感谢您的帮助

另外,我只会说斯威夫特语

编辑

My AppDelegate.swift和快速操作处理程序:

class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

        var isLaunchedFromQuickAction = false

        // Check if it's launched from Quick Action
        if let shortcutItem = launchOptions?[UIApplicationLaunchOptionsKey.shortcutItem] as? UIApplicationShortcutItem {

            isLaunchedFromQuickAction = true
            _ = handleQuickAction(shortcutItem)
        }

        // Return false if the app was launched from a shortcut, so performAction... will not be called.
        return !isLaunchedFromQuickAction
    }

    func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
        completionHandler(handleQuickAction(shortcutItem))
    }

    func handleQuickAction(_ shortcutItem: UIApplicationShortcutItem) -> Bool {

        var quickActionHandled = false
        let type = shortcutItem.type.components(separatedBy: ".").last!
        if type == "QuickAction1" {
            ... // Navigating to VC01, see piece of code above
            quickActionHandled = true
        }
    }
    return quickActionHandled
}
与我在其他应用程序中使用的快速操作处理程序相同。该应用程序的结构为NavigationController-->ViewController1-->ViewController2-->ViewController3。还有一个快速操作导航到ViewController2。它就像一个符咒。 与新应用程序的唯一区别是应用程序结构。我无法通过所有这些Tabbar控制器、NavigationController等赢得导航

编辑2

正如建议的那样,我尝试了另一种来自Apple示例代码()的快速操作处理方法。和现在可以了。部分地

如果我终止应用程序,3D快速动作将完美运行

但是。如果我不终止应用程序,只在后台发送它-快速操作不起作用,在控制台中,我在AppDelegate.swift的开关
shortCutType
下收到相同的旧消息:“警告:尝试显示”),用于导航到“VC01”的快速操作

case ShortcutIdentifier.first.type:
    // Handle shortcut 1 (static).
    let mainSB = UIStoryboard(name: "Main", bundle: nil)
    let tbc = mainSB.instantiateViewController(withIdentifier: "TabBarC") as? TabBarController
    self.window?.rootViewController?.dismiss(animated: true, completion: nil)
    self.window?.rootViewController?.present(tbc!, animated: true, completion: nil)
    handled = true
    break

这段代码经过测试并运行正常。

根据我对您代码的理解,我认为只有三行代码就足够了

let mainSB = UIStoryboard(name: "Main", bundle: nil)
let tbc = mainSB.instantiateViewController(withIdentifier: “TabBarC”) as? TabBarController
self.window?.rootViewController.present(tbc, animated: true, completion: nil)
由于选项卡栏视图控制器似乎仅在情节提要中设置。默认情况下,选择tabbar控制器的第一个选项卡

编辑

“试图呈现…”问题的其他解决方案
您可以设置该标志,并在view controllers viewDidLoad方法中尝试以与代码中相同的方式显示tabBarViewController。

如果您有一个基于情节提要的普通应用程序,则不需要实例化您自己的视图控制器。@ryantxr请继续。我很高兴看到您的解决方案。您是否已通过调试器验证此代码是否正在运行?查看更多AppDelegate可能会有所帮助。您是否将AppDelegate代码与应用程序Shortcuts示例Swift应用程序进行了比较?您的导航控制器是否有分段?@ozzieozumo代码正在运行。我的其他3D快速动作没有问题。我想说这是一个“标准”3D快速动作实现。问题是导航…完全同意这种简化。但是,原始代码也应该可以工作。@Van我刚刚测试了你的建议。应用程序会忽略它。在控制台中,我得到了一个警告:“警告:尝试显示不在窗口层次结构中的视图!”因为您可能从appDidfinishlaunchingOptions调用它,其中根视图还不在前景中。请尝试ro加载项ApplicationIDBECOMEACTIVE,但您需要添加条件,因为即使您从后台回来,此方法也会一直被调用。rootViewController是可选的。您的代码如何具有window?.rootViewController.present。。这应该是一个编译错误,因为您没有展开rootViewController。这是真的密码吗?你能展示更多你实际的AppDelegate代码吗,比如你在哪里调用这些代码等等。看看示例快捷方式应用程序是如何使用didBecomeActive的。你也是这样做的吗?很高兴你取得了进步。在应用程序(不工作的场景)背景时,哪个视图可见?我认为(不是100%确定)您的Shortcut性能需要考虑选项卡栏已经以模式呈现的可能性。如果是,您可以简单地将其关闭,然后调用现有的快捷方式处理程序。我想值得一试。
let mainSB = UIStoryboard(name: "Main", bundle: nil)
let tbc = mainSB.instantiateViewController(withIdentifier: “TabBarC”) as? TabBarController
self.window?.rootViewController.present(tbc, animated: true, completion: nil)