0

My app crashes, not always, at the following method

// overridden
- (void)dismiss
{

    [super dismiss]; 
    [containerView_ removeFromSuperview];
    containerView_ = nil;
}

crash happens at removerFromSuperview.

There is a "show" method as well

// overridden
- (void)show
{

    if (self.parentView == nil)
    {
        // No parentView, create transparent view as parent
        CGSize  frameSize = [UIApplication currentSize];
        containerView_ = [[UIView alloc] initWithFrame:CGRectMake(0, 0, frameSize.height, frameSize.width)];


        containerView_.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
        containerView_.backgroundColor = [UIColor clearColor];
        self.parentView = containerView_;

        if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone)
        {

            if(some condition )
                [[UIApplication sharedApplication].keyWindow.subviews.lastObject addSubview:containerView_];
            else
                [[UIApplication sharedApplication].keyWindow addSubview:containerView_];
        }
        else
        {
            [[UIApplication sharedApplication].delegate.window.rootViewController.view addSubview:containerView_];
        }
    }

    [super show];

    // This is done to allow the Cancel button to be pressed but nothing else - do after [super show]!
    self.superview.userInteractionEnabled = YES;
}

It is strange, that code used to work. I am trying to compile the app for arm64, but I don't understand how that modification impacted those methods.

My app is a non-ARC app, and I cannot go to ARC right now.

Any ideas?

cateof
  • 6,378
  • 19
  • 75
  • 146

3 Answers3

0

Change your code to dismiss view like this.

// overridden

- (void)dismiss
{
   if(containerView_)
    [containerView_ removeFromSuperview];

   containerView_ = nil;
   [super dismiss]; 
}
Vijay Masiwal
  • 1,143
  • 8
  • 12
0

Please check with below code -

- (void)dismiss
{
  if (containerView_)
  {
    [containerView_ removeFromSuperview];
    containerView_ = nil;
    [super dismiss]; 
  }
}
Santu C
  • 2,606
  • 2
  • 11
  • 20
0

Simply check if container view have superview

- (void)dismiss
{
  if ([containerView_ superview])
  {
    [containerView_ removeFromSuperview];
    containerView_ = nil;
    [super dismiss]; 
  }
}
Sudhin Davis
  • 1,962
  • 12
  • 17