ローカル通知が実行され、そのカスタムアクションが実行されるたびに、をTabBarController
から開きたいとします。 、second()
TabBarControllerから特定のViewControllerを表示
func second() {
let storyboard = UIStoryboard.init(name: "Main", bundle: nil)
let tabBarController = storyboard.instantiateViewController(withIdentifier: "Root") as! UITabBarController
let navigationController = storyboard.instantiateViewController(withIdentifier: "Second") as! UINavigationController
tabBarController.present(navigationController, animated: true) {
}
self.window = UIWindow.init(frame: UIScreen.main.bounds)
self.window?.tintColor = UIColor(red: 0.0, green: 0.5, blue: 0.0, alpha: 1.0)
self.window?.rootViewController = tabBarController
self.window?.makeKeyAndVisible()
}
そして、それがうまく機能しています:
func first() {
let storyboard = UIStoryboard.init(name: "Main", bundle: nil)
let tabBarController = storyboard.instantiateViewController(withIdentifier: "Root") as! UITabBarController
let navigationController = storyboard.instantiateViewController(withIdentifier: "First") as! UINavigationController
tabBarController.present(navigationController, animated: true) {
}
self.window = UIWindow.init(frame: UIScreen.main.bounds)
self.window?.tintColor = UIColor(red: 0.0, green: 0.5, blue: 0.0, alpha: 1.0)
self.window?.rootViewController = tabBarController
self.window?.makeKeyAndVisible()
}
セカンド機能:
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping() -> Void) {
switch response.actionIdentifier {
case "first":
DispatchQueue.main.async(execute: {
self.first()
})
case "second":
DispatchQueue.main.async(execute: {
self.second()
})
default:
break
}
completionHandler()
}
だから、それはfirst()
機能だ:私はコードの次の行を使用していますしかし、私はそれを開くことができません二ViewController
最初のものが提示され、第二通知が発射されている間:コンソールで:のViewControllerを提示する警告しようと...
これは役に立たないと思われます。それは1を返します – Mannopson
何も返す必要はありません。 selectedIndexを任意の数値に設定すると、タブバーはタブを選択したインデックスに変更します。 selectedIndex = 0に設定すると、最初のタブに切り替わります。 selectedIndex = 1、2番目のタブ。そうですね、 –
助けてくれてありがとう。私はUITabBarControllerクラスに関する経験はありません。 – Mannopson