嗨,我正在學習 Xcode 來制作 ios 應用程式。我有問題
這是錯誤代碼 -> 執行緒 1:“-[UIViewController back2:]: unrecognized selector sent to instance 0x14fb0e270”
第一個 ViewContorller 代碼 ->
import UIKit
class ViewController: UIViewController {
@IBAction func moveByNavi(_ sender: Any) {
guard let uvc = self.storyboard?.instantiateViewController(withIdentifier: "SecondVC") else {
return
}
self.navigationController?.pushViewController(uvc, animated: true)
}
@IBAction func movePresent(_ sender: Any) {
guard let uvc = self.storyboard?.instantiateViewController(withIdentifier: "SecondVC") else {
return
}
uvc.modalPresentationStyle = .fullScreen
self.present(uvc, animated: true)
}
}
第二個 ViewContorller 代碼 ->
import UIKit
class SecondViewController: UIViewController {
@IBAction func back(_ sender: Any) {
self.presentingViewController?.dismiss(animated: true)
}
@IBAction func back2(_ sender: Any) {
_ = self.navigationController?.popViewController(animated: true)
}
}
每當我單擊第二個視圖控制器上的 back 和 back2 按鈕時,我的模擬器就會停止。并在 appDelegate 上顯示該錯誤代碼。
我檢查了第二個視圖控制器的連接檢查器。后退按鈕連接連接良好。我也沒有其他聯系。我該如何修復我的代碼?
uj5u.com熱心網友回復:
確保使用以下方法實體化視圖控制器:
storyboardInstance.instantiateViewController(withIdentifier: "myViewController")
還要確保故事板場景身份檢查器下的“故事板 ID”值與您在代碼中使用的值(“myViewController”)相同
uj5u.com熱心網友回復:
我認為崩潰的原因是您連接了第二個后退按鈕兩次,您可以在 Storyboard 的“顯示連接檢查器”(上方的右側按鈕)中進行檢查。單擊 Storyboard 中的按鈕,然后單擊“Show the Connections Inspector”按鈕,您將在“Sent Events”中看到連接
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/345141.html
上一篇:如何在Swift中訪問[String:Any]字典上的值
下一篇:鍵盤覆寫UITextView
