UISplitView: Why are there multiple DetailController-Instances? (new one on each segue)

▼魔方 西西 提交于 2019-12-23 05:09:05

问题


I've noticed that in a Master-Detail UISplitView iPhone app, I dont have one single instance of my DetailController and getting that reused by setting new content, instead it seems that on each segue/everytime I navigate to the Detail View, a new instance of DetailController gets created by the segue and has to be filled with content?

Why is that? Through debugging I can see that there is at least one DetailController instance staying alive all the time but not used on iPhone, and everytime I segue from Master to Detail, a new instance is created.

I would like to just use one instance to be more efficient (memory,speed) ... Is there some easy switch to change this behaviour, or would I have to implement Singleton in my DetailController to prevent additional instances from being created?

By the way, I am using a new master-detail-project with apple-code.


回答1:


After further search, found this possible workaround (possible alternative instead of using singleton): Replace segue creating new instance

Basically it says to stop the segue from happening by returning NO in -shouldPerformSegueWithIdentifier:sender:, after setting the new content in the old instance. Might work on iPad, but on iphone the segue animation is needed to bring the detail view up.



来源:https://stackoverflow.com/questions/33806621/uisplitview-why-are-there-multiple-detailcontroller-instances-new-one-on-each

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!