UISplitView:为什么会有多个DetailController实例? (每个segue上有一个新的) [英] UISplitView: Why are there multiple DetailController-Instances? (new one on each segue)

查看:81
本文介绍了UISplitView:为什么会有多个DetailController实例? (每个segue上有一个新的)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到,在主详细信息UISplitView iPhone 应用中,我没有一个 实例,而是通过设置新内容,相反,似乎在每个segue/每次我导航到详细信息视图"时,segue都会创建一个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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆