我正在尝试使用Storyboard和Swift 2.0开发应用程序。 我有一个带有UITableView的SideMenuController和一个CenterViewController。每次我点击侧面菜单上的一行时,我都会执行以下操作:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if (indexPath.row == 0){
self.sideMenuController()?.performSegueWithIdentifier(CenterSegue, sender: nil)
}else if(indexPath.row == 1){
self.sideMenuController()?.performSegueWithIdentifier(SaloniSegue, sender: nil)
}else if(indexPath.row == 2){
...
}
一切似乎都运行良好,但在一点点测试中,我已经指出旧的视图控制器仍在堆栈中。
有没有办法将它们弹出来防止RAM重载?
答案 0 :(得分:0)
是的,您可以通过访问navigationController.viewController属性来执行此操作 看看这个功能......你会有所了解...... 而不是推......你可以在需要的时候执行。
func pushController()
{
// Variable to check whether viewcontroller is present in memory or not
var isFound = false;
// searching in array of viewControllers of navigationController
for item in self.navigationController!.viewControllers
{
if(item.isKindOfClass(ViewController) == true)
{
isFound = true;
}
}
if(isFound == false)
{
// LoadView then push it
self.navigationController?.pushViewController(yourViewController, animated: true);
}
else
{
// View Is in memory so just pop to it
self.navigationController?.popToViewController(yourViewController, animated: true);
}
}
答案 1 :(得分:-2)
首先,改变你的导航结构,摆脱汉堡包/左菜单,它绝对是sux。