로컬 알림 이 실행되고 해당 사용자 지정 동작이 수행 될 때마다에서 특정 ViewController
을 열려고합니다. , 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, 두 번째 탭. 등등 –
도와 줘서 고마워. UITabBarController 클래스에 대한 경험이 없습니다. – Mannopson