问题
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