Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>So, the short answer is yes, this "paradigm" is a bad implementation of dealing with UIViewControllers. I would suggest going and reading Apple's View Controller Programming Guide, which outlines the correct implementation, but here's a quick synopsis:</p> <p>Your MasterViewController, from what I gather, manages these other two UIViewControllers, ThinkOfViewController and PicturePrimeViewController. When you are adding or removing the views of a view controller from the screen, you don't add or remove the views to the MasterViewController. The whole point of a view controller is to manage the "showing" or "hiding" of its view. I put showing and hiding in quotes because you're not actually showing or hiding them. You are pushing and popping them off of the view hierarchy, and this is done with a UINavigationController. Each UIViewController knows the UINavigationController that it is being controlled by (thus, UINavigationControllers are known as "controllers of controllers"), and you can thus push a view controller onto the stack by saying</p> <pre><code>[self.navigationController pushViewController:vcToBePushed animated:YES]; </code></pre> <p>When the view controller that is on top of the stack is to be removed, you simply have to say</p> <pre><code>[self.navigationController popViewControllerAnimated:YES]; </code></pre> <p>Pushing or popping a UIViewController onto or off of the stack means the view controller takes its view with it, and displays it or removes it from on screen. So that covers, in the tightest nutshell imaginable, UIViewController view management.</p> <p>The other issue, regarding the EXC_BAD_ACESS crash, means that you are trying to access memory that has already been allocated for another object. I suspect the culprit is here:</p> <pre><code>if (randomNumber == 0) { self.flashTextViewIsDisplayed = NO; ThinkOfViewController *thinkVC = [[ThinkOfViewController alloc] initWithNibName:@"ThinkOfViewController" bundle:nil]; self.thinkOfViewController = thinkVC; [thinkVC release]; self.picturePrimeViewIsDisplayed = YES; [self.view addSubview:self.thinkOfViewController.view]; } </code></pre> <p>The problem is that you release thinkVC before it has had a chance to be retained by the MasterViewController's view (which happens in self.view addSubview:). Thus, self.view is adding a pointer to an object whose memory just got added back to the heap. Scrapping your add/removeSubview methodology for the push/pop methodology I just outlined will keep that sort of memory issue from happening.</p> <p>I hope this helps, but let us (us being SO) know if you still have issues.</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