iOS開發中界面跳轉有兩種方式,上下跳轉和左右跳轉。
下跳轉_TO:
let secondViewController = SecondViewController() self.presentViewController(secondViewController, animated: true, completion: nil)
上跳轉_BACK:
dismissViewControllerAnimated(true, completion: nil)
右跳轉_TO:
(將新的視圖控制器PUSH到navigationController中,相當於入棧操作)
let secondViewController = SecondViewController() self.navigationController!.pushViewController(secondViewController, animated: true)
右跳轉帶傳值:
//屬性傳值,vc為將跳轉到的頁面 let vc = CarouselInfoWebController() //para為要傳輸到的變量 var para = Dictionary<String,String>() para["title"] = messageList[row].title para["content"] = messageList[row].content //translatePara是定義在vc頁面的接收參數的變量 vc.translatePara = para vc.hidesBottomBarWhenPushed = true self.navigationController?.pushViewController(vc, animated: true)
左跳轉_BACK:
(將當前視圖控制器從導航視圖控制器堆棧中移除,從而返回到了上一級界面)
( - ) BACK_到上一級:
let firstViewController = FirstViewController() self.navigationController?.popViewControllerAnimated(true)
( - ) BACK_指定界面:
// 獲得視圖控制器中的某一視圖控制器 let viewController = self.navigationController?.viewControllers[0] self.navigationController?.popToViewController(viewController as! UIViewController, animated: true)
( - ) BACK_根視圖:
self.navigationController?.popToRootViewControllerAnimated(true)
根視圖的設置需要在AppDelegate中設置:
var window: UIWindow? func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { var firstViewController = FirstViewController() var rootNavigationViewController = UINavigationController(rootViewController: firstViewController) self.window!.rootViewController = rootNavigationViewController return true }