![](/img/trans.png)
[英]Receiver has no segue with identifier in self.performSegue(withIdentifier, sender)
[英]App crashing when trying to use performSegue(withIdentifier: , sender: )
如果我的應用程序是通過Firebase發送的通知打開的,我目前正在嘗試立即執行一個新的ViewController。
我正在嘗試使用代碼self.performSegue(withIdentifier: "testSegue", sender: nil)
執行segue,其中“testSegue”是我的Storyboard中從ViewController到SecondViewController(不同類)的segue的標識符。
問題是這一行正在崩潰我的應用程序,我不能輕易調試這個,因為我從通知啟動應用程序,而不是從Xcode啟動。
我還通過添加一個在5秒后運行此行的Timer來延遲代碼,以確定崩潰發生時它在此行,並且還嘗試使用present(viewControllerToPresent: ...)
。
如果有人可以指出崩潰發生的原因,或者如何在這種情況下調試錯誤,或者任何其他方法讓它自動進入ViewController,那將是非常好的,謝謝。
來自AppDelegate.swift的一些額外代碼:
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
print(userInfo)
let url = userInfo["url"]
print("url is: \(String(describing: url))")
if url != nil {
vc.defaults.set("\(String(describing: url))", forKey: "urlDef")
vc.defaults.set(true, forKey: "hasRun")
initialVC.testingFunc()
print("Func done")
}
completionHandler(UIBackgroundFetchResult.newData)
print("Func finished")
}
ViewController.swift中的一些額外代碼
var funcTimer = Timer()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
func testingFunc() {
funcTimer = Timer.scheduledTimer(timeInterval: 5, target: self, selector: #selector(self.triggerSegue), userInfo: nil, repeats: false)
print("The timer has begun")
}
func triggerSegue() {
print("Trigger segue func has begun")
self.performSegue(withIdentifier: "testSegue", sender: nil)
}
在演示viewController時切換到主線程。
func triggerSegue() {
DispatchQueue.main.async {
self.performSegue(withIdentifier: "testSegue", sender: nil)
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.