![](/img/trans.png)
[英]How do I create a new Swift project without using Storyboards?
[英]How to Push a New View Without Storyboards Swift
首先,我根本不想使用故事板。 我能夠“呈現”目標視圖控制器,但我無法通過頂部的標准iOS后退按鈕顯示它。 我的理解是我可以通過推動控制器而不是呈現它來實現這一點。 我沒有任何錯誤,但沒有任何反應。
在按鈕上單擊此代碼即可運行。 注釋代碼成功呈現了ForgotPasswordPage:
//更改忘記密碼頁面
func forgotPasswordSwitch(sender: UIButton!) {
//let ForgotPassword:ForgotPasswordPage = ForgotPasswordPage()
//self.presentViewController(ForgotPassword, animated: true, completion: nil)
let ForgotPassword = ForgotPasswordPage()
self.navigationController?.pushViewController(ForgotPassword, animated: true)
}
您必須手動創建UINavigationcontroller
以獲取后退欄。 為此,您可以使用此答案中的代碼,通過使用此代碼實現此目的:
self.window = UIWindow(frame: UIScreen.mainScreen().bounds) var nav1 = UINavigationController() var mainView = ViewController() //ViewController = Name of your controller nav1.viewControllers = [mainView] self.window!.rootViewController = nav1 self.window?.makeKeyAndVisible()
這里只需將您想要在導航控制器下的所有ViewControllers添加到數組中,然后在它們之間進行推送。
希望有所幫助,朱利安
我知道有時以編程方式開發應用程序要好得多,但有很多時候Storyboard可以為您節省大量時間。 你只是在這種情況下使用它......
1)在Storyboard中,本地化要啟用的視圖控制器以進行推送
2)選擇它並在頂部欄中找到“編輯器”
3)選擇Editor-> Embed In-> Navigation Controller
而現在你的視圖控制器已經准備好推送了
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.