3D触摸到UITabView

时间:2015-10-30 03:05:37

标签: ios swift 3dtouch

我正在使用tabViewController并想知道如何从主屏幕显示3D触摸操作。我已经有了代码,但似乎无法显示特定的标签;我只能得到一个窗口。我的AppDelagate.swift在下面。有什么帮助吗?

enter image description here

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

}

1 个答案:

答案 0 :(得分:0)

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

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
        ...
}