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

  • SEARCH
  • Home
  • 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 7036225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:23:55+00:00 2026-05-28T01:23:55+00:00

I am struggling with understanding why the first method below works for hiding and

  • 0

I am struggling with understanding why the first method below works for hiding and removing a subview of a view. In this first method I pass the pointer by reference. In the second method, which is less general, I have a delegate method designed for removing a specific view. I would like to use the first method, because I have several views that I would like to apply this too. I should mention that the first method works without fail as long as it is called within the implementing class. It fails when I call it from the view controller that I wish to dismiss. I get an EXC_BAD_ACCESS on the removeFromSuperview line when it fails in the first method.

-(void)closeView:(UIViewController **)viewController
{
 [UIView transitionWithView:self.view 
                   duration:UINavigationControllerHideShowBarDuration
                    options:UIViewAnimationOptionCurveLinear
                 animations:^
  {
   [[*viewController view] setAlpha:0.0];
  }
                 completion:^(BOOL finished)
  {   
   [[*viewController view] removeFromSuperview];
   [*viewController release], *viewController = nil;
  }];
}

-(void)closeButtonClicked
{
 [delegate closeView:&self];
}

//
// This method works without fail:
//

-(void)closeView
{
 [UIView transitionWithView:self.view 
                   duration:UINavigationControllerHideShowBarDuration
                    options:UIViewAnimationOptionCurveLinear
                 animations:^
  {
   // In this context viewController is defined in the class interface
   [[viewController view] setAlpha:0.0];
  }
                 completion:^(BOOL finished)
  {      
   [[viewController view] removeFromSuperview];
   [viewController release], viewController = nil;       
  }];
}

-(void)closeButtonClicked
{
 [delegate closeView];
}
  • 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-28T01:23:56+00:00Added an answer on May 28, 2026 at 1:23 am

    First of all, it is not according to the style guides, and not a good idea in general, to do a release of the viewController within a method like this. It will get you into trouble quickly. If the caller of this method is responsible for the viewController (it has done the retain), then it should release it as well. This is likely the cause of the first method not working from within the viewcontroller itself.

    In the second method you do not pass in the viewController as parameter, which means it needs to be defined in the context.

    If you don’t release the viewController in this method, then you don’t need to set its variable to nil either, and you can simply pass it as normal parameter:

    -(void)closeView:(UIViewController *)viewController
    {
     [UIView transitionWithView:self.view 
                       duration:UINavigationControllerHideShowBarDuration
                        options:UIViewAnimationOptionTransitionCrossDissolve
                     animations:^
      {
        [[viewController view] removeFromSuperview];
      }
                     completion:nil];
    }
    

    you would then do this at the call-site:

    [self closeView:childViewController];
    [childViewController release]; childViewController = nil;
    

    It safe to release the child in this way before the animation is done, because the animations block implicitly retains all objects referenced from the block, including the viewController parameter. Therefore, the child’s dealloc is not called until the animations block releases it.
    This does not work in your first code example, because you pass a pointer to a variable. That is, the animations block does not know it needs to retain the child.

    BTW, I am not sure why you want to set the alpha, in the example above I show that you can also remove the view already in the animations block. See more about that in the UIView Class Reference.

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

Sidebar

Related Questions

I am really struggling with this one. Below is an image of a layout
I'm struggling with understanding how Rake processes Cucumber tasks. I'm probably doing this wrong,
I've been struggling with understanding how C++ classes include other classes. I'm guessing this
I have been struggling with this issue for a few hours now without understanding
This is my first attempt at understanding Linq to Entity coming from Net Tiers.
Been struggling with this simple selector problem a couple of hours now and must
im struggling with syntax here: hopefully this question is v simple, im just miising
A coworker has been struggling with this problem. The desired result is an installable
I am struggling understanding what a clustered index in SQL Server 2005 is. I
I'm struggling to get my head round how the HiLo generator works in NHibernate.

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.