2017-09-22 2 views
0

저는 앱의 빠른 동작을 나타냅니다. 그것은 잘 작동합니다. 그래서 AppDelegate에 내가이 같은 shortcutItem 확인하고 completionHandler 함수를 호출하고 있습니다 :Swift : 빠른 작업으로 AppDelegate에서 특정 TabBar 탭에 액세스하는 방법?

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

    completionHandler(handleShortcut(shortcutItem: shortcutItem)) 
} 

지금 나는 handleShortcut 기능의 특정 탭을 열고 싶지만이 전혀 작동하지 않습니다. 이 storyboardID의와 rootViewController로 추가로 내가보기로로드 시도,하지만 난이 전혀 작동 것인지도 모르겠습니다 또는이 할 수있는 올바른 방법 인 경우

let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle:nil) 
    let vc = storyBoard.instantiateViewController(withIdentifier: "tabBar") 
    self.window = UIWindow(frame: UIScreen.main.bounds) 
    self.window?.rootViewController = vc 
    self.window?.makeKeyAndVisible() 

하지만 분명히 내가 예를 들어 tabBarController?.selectedIndex = 2을 사용하여 세 번째 탭에 액세스 할 수 없습니다.

빠른 동작을 통해 내 tabBarController의 다른 탭에 액세스하고 표시 할 수있는 올바른 방법은 무엇입니까?

답변

0

나는 솔루션에왔다,하지만이 그것을 할 수있는 최선의 방법 인 경우 확실하지 않다 :

if shortcutItem.type == "com.xxx.openHelp" { 
      let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle:nil) 
      let vc = storyBoard.instantiateViewController(withIdentifier: "tabBar") 
      self.window = UIWindow(frame: UIScreen.main.bounds) 
      self.window?.rootViewController = vc 
      let myTabBar = self.window?.rootViewController as! UITabBarController 
      myTabBar.selectedIndex = 3 
      self.window?.makeKeyAndVisible() 
     } 
관련 문제