问题描述
我在这里遇到了问题.我正在使用 performSegueWithIdentifier
呈现视图.一切顺利.问题是,作为测试,我只有2个viewControllers,其中包含一些数据,并且我有两个按钮,用于将segue调用回另一个VC.如果我继续执行Segues,则可以清楚地看到每两个Segues的内存使用量增加了约0.4Mb.这告诉我,视图并没有从视图堆栈中删除/删除,而只是在使用内存.我想知道通过使用 performSegueWithIdentifier
来消除呈现另一个视图的视图的正确方法(当然,在完成呈现视图之后,我猜它不会起作用)./p>
您能指出我正确的方向吗?我找到了一些试图做到这一点的Objective-C代码,但是它非常广泛,而且我对Objective-C并不了解,所以这让我很难理解.
预先感谢您的帮助!
干杯!
我正在做手动搜索".我的意思是我有两个独立的视图控制器.它们没有嵌入任何导航VC或类似的东西中.我正在使用显示"类型的自适应Segue".
如果您的目标是始终保留一个VC,并且由于您已经有手动设置,那么您可以做的是,在显示下一个VC之后,您可以弹出根中现有的VC,像这样将目标VC分配为您的根VC
class ManualSegue:UIStoryboardSegue {覆盖func perform(){sourceViewController.presentViewController(destinationViewController,animation:true){self.sourceViewController.navigationController?.popToRootViewControllerAnimated(false)UIApplication.sharedApplication().delegate?.window ??.rootViewController = self.destinationViewController}}}
I am running into a problem here. I am presenting views with performSegueWithIdentifier
. Everything goes smoothly. The problem is that as a test, I only have 2 viewControllers with some data in them and I have two buttons that call a segue back to the other VC. If I keep performingSegues, you can clearly see that the memory usage goes up every two segues by around 0.4Mb. This tells me that the Views are not being deleted/removed from the view stack and are just using memory. I would like to know the correct way of getting rid of the view that presents the other view by using performSegueWithIdentifier
(of course, after it finished presenting the view, else it will not work I guess).
Could you point me in the right direction? I found some objective-c code that tried to do this but it was very extensive and I don't know much about objective-C, so it was a little hard for me to understand.
Thank you in advance for your help!
Cheers!
Edit:
I am doing a "manual segue". By this I mean I have two view controllers standing on their own. They are not embedded in any navigationVCs or something like that. I am using an "Adaptive Segue" of type "Show".
If your goal is to always keep one VC, and since you already have a manual segue, what you can do is, after presenting the next VC you can pop the existing VC from the root and assign the destination VC as your root VC like so
class ManualSegue: UIStoryboardSegue {
override func perform() {
sourceViewController.presentViewController(destinationViewController, animated: true) {
self.sourceViewController.navigationController?.popToRootViewControllerAnimated(false)
UIApplication.sharedApplication().delegate?.window??.rootViewController = self.destinationViewController
}
}
}
这篇关于在Swift中进行序列化之后,从堆栈中删除(删除)view/viewController的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!