How to load UIViewController from NIB using placeholders?
I have a UIViewController that I want to load from the NIB that has a proxy object (placeholder) defined in it. The first time I load it, I go through this rigamarole:
MyViewController *screen = [[MyViewController alloc] init];
NSDictionary *proxyDict = [NSDictionary dictionaryWithObject:myObject forKey:@"MyProxy"];
NSDictionary *optionsDict = [NSDictionary dictionaryWithObject:proxyDict forKey:UINibExternalObjects];
[[NSBundle mainBundle] loadNibNamed:@"MyViewController" owner:screen options:optionsDict];
So this sets up a proxy object declared as "MyProxy" in the NIB file to point to an already existing object myObject
. It works a lot.
Now if I go to another screen and fire a low memory alert it dumps the view. when I return to this screen, it will automatically reload the view, which has no room for a manually defined dictionary of options to configure proxy objects, and then it crashes trying to find an object to reference "MyProxy".
How can I make this work?
+2
source to share
2 answers