Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7435449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:04:36+00:00 2026-05-29T10:04:36+00:00

thank you for your time, (As a side note, this question pertains mostly to

  • 0

thank you for your time, (As a side note, this question pertains mostly to iOS 4.2.3, I am aware some of these issues could be resolved with moving the code base to iOS 5, however we would like to release this app for phones running iOS 4 as well.)

I have a “MasterViewController” that is in charge of calling and dismising other UIVIewControllers.

First we trigger a new one:

In MasterViewController.m

-(IBAction)triggerPrime:(id)sender {

    [self clearHomeScreen];

    NSUInteger randomNumber = arc4random() % 2;

    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];        
    }

    else if (randomNumber == 1) {

        self.picturePrimeViewIsDisplayed = NO;

        FlashTextPrimeViewController *flashVC = [[FlashTextPrimeViewController alloc] initWithNibName:@"FlashTextPrimeViewController" bundle:nil];

        self.flashTextPrimeViewController = flashVC;

        [flashVC release];

        self.flashTextViewIsDisplayed = YES;        
        [self.view addSubview:self.flashTextPrimeViewController.view];

    }

Let’s say that our randomNumber is 0, and it adds the ThinkOfViewController to the subview, (This is a very basic screen, it essentially displays some text with some assets animating:

In ThinkOfViewController.m

- (void)viewDidLoad {

    [super viewDidLoad];

    self.thinkOf.alpha = 0.0;

    self.dot1.alpha = 0.0;

    self.dot2.alpha = 0.0;

    self.dot3.alpha = 0.0;

    self.background.alpha = 0.0;

    [self animateViews];

}

-(void)animateViews {

    [UIView animateWithDuration:0.25 animations:^ {

         self.background.alpha = 1.0;       

    }completion:^(BOOL finished) {        

        [UIView animateWithDuration:0.75 delay:0.00 options:UIViewAnimationCurveEaseIn animations:^ {

            self.thinkOf.alpha = 1.0;

        }completion:^(BOOL finished) {

            [UIView animateWithDuration:0.20 delay:0.60 options:UIViewAnimationCurveEaseIn animations:^ { 

                self.dot1.alpha = 1.0;

            }completion:^(BOOL finsihed) {

                [UIView animateWithDuration:0.20 delay:0.60 options:UIViewAnimationCurveEaseIn animations:^ {

                    self.dot2.alpha = 1.0;

                }completion:^(BOOL finished) {

                    [UIView animateWithDuration:0.20 delay:0.60 options:UIViewAnimationCurveEaseIn animations:^ {

                        self.dot3.alpha = 1.0;

                    }completion:^(BOOL finished) {

                        [UIView animateWithDuration:0.50 delay:0.60 options:UIViewAnimationCurveEaseInOut animations:^{

                            self.view.alpha = 0.0;

                        }completion:^(BOOL finished) {

                            NSLog(@"all animations done");

                            [[NSNotificationCenter defaultCenter] postNotificationName:@"removeThinkOfView" object:nil];

                        }];

                    }];

                }];

            }];

        }];

    }];
}

As you can see, once the animation sequence is finished, I post a notification to NSNotificationCenter (which resides in the MasterViewController) to remove this viewController.

In MasterViewController.m

-(void)removeThinkOfView {

    [self.thinkOfViewController.view removeFromSuperview];

    [self showPicturePrime];

}

-(void)showPicturePrime {

        if (self.picturePrimeViewController == nil) {

            PicturePrimeViewController *pVC = [[PicturePrimeViewController alloc] initWithNibName:@"PicturePrimeViewController" bundle:nil];

            self.picturePrimeViewController = pVC;

            [pVC release];

            [self.view addSubview:self.picturePrimeViewController.view];

        }

        else {    

            PicturePrimeViewController *pVC = [[PicturePrimeViewController alloc] initWithNibName:@"PicturePrimeViewController" bundle:nil];

            self.picturePrimeViewController = pVC;

            [pVC release];

            [self.view addSubview:self.picturePrimeViewController.view];

        }

}

Now a picturePrimeViewController is loaded and added to the subview, everything loads and displays fine. Now, to get a new prime, you simple swipe for a new one.

In picturePrimeViewController.m

-(void)handleSwipeFromRight:(UISwipeGestureRecognizer *)gestureRecognizer {
    if (!transitioning) {

        [self performTransition];

    }

}

-(void)performTransition {

    CATransition *transition = [CATransition animation];

    transition.duration = 1.0;

    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];

    transition.type = kCATransitionPush;

    transition.subtype = kCATransitionFromLeft;

    transitioning = YES;

    transition.delegate = self;

    [self.view.layer addAnimation:transition forKey:nil];

    [UIView animateWithDuration:0.5 animations:^ {

        self.view.alpha = 0.0;

    }completion:^(BOOL finished) {

        NSLog(@"Transition Animation Complete");

    }];

}

-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {

    transitioning = NO;

    [[NSNotificationCenter defaultCenter] postNotificationName:@"nextPrime" object:nil];

} 

Now in the animationDidStop: Method, i again post another notification to the NSNotificationCenter back to the MasterViewController to signal another prime.

In MasterViewController.m

-(void)nextPrime {

    if (self.picturePrimeViewIsDisplayed) {

        [self.picturePrimeViewController.view removeFromSuperview];

        self.picturePrimeViewController = nil;

        [self showAPrime];

    }

    if (self.flashTextViewIsDisplayed) {

        [self.flashTextPrimeViewController.view removeFromSuperview];

        self.flashTextPrimeViewController = nil;

        [self showAPrime];

    }

}

However! Upon swiping the right, the view animates properly but then I get a bad access crash when the ThinkOfViewController is attempting to dealloc it’s UIViews. So for some reason, it is taking that the ThinkOfViewController a long time to dealloc, when I assumed when I called [self.thinkOfViewController removeFromSuperview], it should of been removed immeditately.

(Side note, the textFlashViewController has no problems, the only problems are comming with this ThinkOfViewController).

Is this paradigm I set up a bad implmentation of dealing with UiViewController’s comming in and out? I have read that delegation can help in this instance, I’m just not sure how that works.

If any of you have any ideas, I would be so grateful, as I have mined through forums and documentations and cannot see a solution to my rather custom implmentation of dealing with these views.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T10:04:37+00:00Added an answer on May 29, 2026 at 10:04 am

    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:

    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

    [self.navigationController pushViewController:vcToBePushed animated:YES];
    

    When the view controller that is on top of the stack is to be removed, you simply have to say

    [self.navigationController popViewControllerAnimated:YES];
    

    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.

    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:

    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];        
    }
    

    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.

    I hope this helps, but let us (us being SO) know if you still have issues.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Thank you for your interesting in my question. You can help me out from
Thank you for taking the time to read this. I looked over Stack Overflow
I've been dealing with this problem for quite some time. What I am trying
first of all thanks for taking your time! I'm a junior Dev, working with
Ok. here's the operations i successfully code so far thank's to your help: Adittion:
Thank you all for your help. A number of you posted (as I should
Thanks for your answers to my previous question about GUI in java . I
Hello and thanks for your opinion. I am creating a webservice. This webservice will
This problem has been solved thanks to your suggestions. See the bottom for details.
i really need your help with a CSS-Layout. I tried a few time, however

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.