寫ios應(yīng)用的頁面切換不比寫網(wǎng)頁容易锈麸,網(wǎng)頁應(yīng)用可通過路由控制頁面的跳轉(zhuǎn)镀脂,而 ios 應(yīng)用沒有路由概念,所以頁面跳轉(zhuǎn)相對比較麻煩忘伞。
例如編輯消息后點擊發(fā)送按鈕薄翅,當(dāng)發(fā)送成功后需跳轉(zhuǎn)到首頁的操作可以這樣寫:
let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let FirstViewController = storyBoard.instantiateViewController(withIdentifier: "FirstViewController") as! FirstViewController
self.navigationController?.pushViewController(FirstViewController, animated: true)
前提是 storyboard 文件里發(fā)送按鈕的 viewControler 之前連接有一個 navigationController 。
假如是在當(dāng)前頁彈出一個頁面的氓奈,例如在點擊收藏的時候需要判斷用戶是否已登錄翘魄,未登錄則需要彈出登錄框,可以這樣寫
let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let LoginViewController = storyBoard.instantiateViewController(withIdentifier: "LoginViewController") as! LoginViewController
self.present(LoginViewController, animated: true, completion: nil)
關(guān)閉當(dāng)前視圖則調(diào)用
self.dismiss(animated: true, completion: nil)