我正在使用一个tabViewController并且想知道如何在主屏幕上显示一个选项卡来进行3D触摸操作。我已经有了代码,但似乎无法显示特定的选项卡;我只能得到一个窗口。我的AppDelagate.swift在下面。有什么帮助吗?
ios - 3D触摸UITabView-LMLPHP

enum ShortcutIdentifier: String
{
    case First
    case Second

    init?(fullType: String)
    {
        guard let last = fullType.componentsSeparatedByString(".").last else {return nil}
        self.init(rawValue: last)
    }

    var type: String
        {
        return NSBundle.mainBundle().bundleIdentifier! + ".\(self.rawValue)"
    }

}

func handleShortcutItem(shortcutItem: UIApplicationShortcutItem) -> Bool
{
    var handled = false

    guard ShortcutIdentifier(fullType: shortcutItem.type) != nil else {return false}
    guard let shortcutType = shortcutItem.type as String? else {return false}

    switch (shortcutType)
    {
    case ShortcutIdentifier.First.type:
        handled = true

        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let navVC = storyboard.instantiateViewControllerWithIdentifier("sourcesview") as! UINavigationController
        if let tabBarController = navVC.topViewController as? UITabBarController {
            tabBarController.selectedIndex = 4
        }
        self.window?.rootViewController?.presentViewController(navVC, animated: true, completion: nil)

        break
    case ShortcutIdentifier.Second.type:
        handled = true

        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let navVC = storyboard.instantiateViewControllerWithIdentifier("searchview") as! UINavigationController
        self.window?.rootViewController?.presentViewController(navVC, animated: true, completion: nil)

        break
    default:
        break
    }


    return handled

}

最佳答案

您必须在selectedTab上设置UITabBarController属性。我假设您从nib加载的UINavigationController包含一个UITabBarController作为顶视图控制器,因此在从nib加载导航控制器之后,您必须访问选项卡栏控制器并将选定的选项卡属性设置为所需的选项卡。

switch (shortcutType)
    {
    case ShortcutIdentifier.First.type:
        handled = true

        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let navVC = storyboard.instantiateViewControllerWithIdentifier("sourcesview") as! UINavigationController
        if let tabBarController = navVC.topViewController as? UITabBarController {
            tabBarController.selectedIndex = 1
        }
        self.window?.rootViewController?.presentViewController(navVC, animated: true, completion: nil)

        break
        ...
}

关于ios - 3D触摸UITabView,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33428001/

10-09 16:33