UISplitView:为什么会有多个DetailController实例? (每个segue上有一个新的) [英] UISplitView: Why are there multiple DetailController-Instances? (new one on each segue)
问题描述
我注意到,在主详细信息UISplitView
iPhone 应用中,我没有DetailController
的新实例,并且必须填充内容?
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?
那是为什么?通过调试,我可以看到至少有一个DetailController
实例一直处于活动状态,但没有在iPhone上使用,并且每次我从Master切换到Detail时,都会创建一个新实例.
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.
我只想使用一个实例来提高效率(内存,速度)...是否可以通过一些简单的开关来更改此行为,还是必须在DetailController
中实现Singleton以防止其他实例出现?被创建吗?
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?
顺便说一句,我正在使用一个新的带有苹果代码的master-detail-project.
By the way, I am using a new master-detail-project with apple-code.
推荐答案
进一步搜索后,发现了这种可能的解决方法(可能的替代方法,而不是使用单例): 替换segue创建新实例
After further search, found this possible workaround (possible alternative instead of using singleton): Replace segue creating new instance
基本上,它说在旧实例中设置新内容后,通过在-shouldPerformSegueWithIdentifier:sender:中返回NO来停止segue的发生.可以在iPad上使用,但是在iphone上,需要segue动画才能显示详细视图.
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.
这篇关于UISplitView:为什么会有多个DetailController实例? (每个segue上有一个新的)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!