2017-04-10 17 views
0

在我的節目,一些viewControllers之間的轉換都通過下面的代碼編程方式管理:斯威夫特:安全有關presentScene()的做法

let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil) 
let newViewController = storyBoard.instantiateViewController(withIdentifier: "NewViewController") as! NewViewController 
self.present(newViewController, animated: true, completion: nil) 

我一直在想,如何安全的做法,這是的。當currentScene被調用時,它是否會做任何事情來「擦除」它下面的屏幕,還是隻是在現有的頂部堆疊更多的視圖?如果不是,它是如何工作的?這也是管理這種程序轉換的最佳方式(就性能而言)?

回答

1

首先,除了Main之外,您不需要每次都創建UIStoaryboard的對象,除非您有不同的名稱。修改你的代碼:

let newViewController = self.storyBoard!.instantiateViewController(withIdentifier: "NewViewController") as! NewViewController 

現在來你的問題!當您在另一個UIViewControllerUINavigationController上呈現任何UIViewController時,所呈現的控制器沒有堆疊。

簡而言之,您將展示一個UIViewController模式上的陳述者UIViewController。這可以發生在任何UIViewController沒有任何關係規則。主持人應負責解僱其提交的風險投資。

希望這會消除你的懷疑。