首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >3D触摸到UITabView

3D触摸到UITabView
EN

Stack Overflow用户
提问于 2015-10-30 11:05:37
回答 1查看 449关注 0票数 1

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

代码语言:javascript
复制
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

}
EN

回答 1

Stack Overflow用户

发布于 2015-10-30 23:25:21

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

代码语言:javascript
复制
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
        ...
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33428001

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档