![](/img/trans.png)
[英]Unnecessary pushing of registers to the stack when others with the same value exist, why?
[英]Why is button not pushing to ViewController?
我已經使用 Firebase 在我的 iOS 應用程序中成功創建了登錄/注冊功能,但是當用戶登錄時我遇到了問題。
我正在嘗試創建一個菜單頁面 (HomeVC),其中一個按鈕通向一個新視圖 controller(第二個視圖控制器),但是當按下按鈕時沒有任何反應。
當我從“HomeVC”添加一個 segue 到“SecondViewController”時,該按鈕有效,但視圖 controller 顯示為模態並且不是導航的一部分。
class HomeViewController: UIViewController {
@IBOutlet weak var button: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func didTapButton(){
navigationController?.pushViewController(SecondViewController(), animated: true)
}
}
class SecondViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.title = "MY SECOND PAGE"
view.backgroundColor = .red
let storyboard = UIStoryboard(name: "Main" , bundle: nil) // Assuming "Main" is your storyboard name
let vc = storyboard.instantiateViewController(withIdentifier: "aaaa") // add "aaaa" as storyboard id for that view controller in Main storyboard
navigationController?.pushViewController(vc, animated: true)
你也可以這樣試試
你必須給 Storyboard Id 作為SecondViewController
let viewController: SecondViewController = self.storyboard?.instantiateViewController(withIdentifier: "SecondViewController") as! SecondViewController
self.navigationController?.pushViewController(viewController, animated: true)
或者這樣試試
self.navigationController?.present(SecondViewController(), animated: true, completion: nil)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.