Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can one create a generic (container)controller that will recieve as input another controller
    text
    copied!<p>In the app im creating there are many pages that look mostly the same with some part which is different. To handle this kind of situation i created a container controller that contains a subview. I want this subview to be filled by the contents of another controller (and its associated nib) which i will created dynamically as needed based on context.</p> <p>I have the following method somewhere</p> <pre><code>- (void) someAction { UIViewController* contentController = [[MyContentController alloc] init]; UIViewController* containerController = [[MyContainerController alloc] initWithContentController:contentController]; [navigationController pushViewController:pageController animated:YES]; [contentController release]; [containerController release]; } </code></pre> <p>In MyContainerController.m i retain the controller in a property</p> <pre><code>- (id)initWithContentController:(UIViewController *)aContentController { if ((self = [super initWithNibName:@"MyContainerController" bundle:nil])) { contentController = aContentController; } return self; } </code></pre> <p>Later in viewDidLoad i do the following</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; [contentViewContainer addSubview:contentController.view]; } </code></pre> <p>contentViewContainer is the view that's supposed to hold the page specific info. Unfortunatly this fails with EXC_BAD_ACCESS. The funny thing is that if i alloc and init the content controller from within viewDidLoad everything works. It seems that i cant pass a contoller i allocated from another place. Can anyone assist.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload