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,608
  • 25
  • 79
  • 153
  • the issue is due to child - parent views, this code works well in iOS 6-7 but not in iOS 8, you would have to check the parent views of the child views and views hierarchy. App crashes when you try to remove and sometimes when you add a child view. – Omer Waqas Khan May 25 '15 at 10:33
  • Getting any error log ? – Omer Waqas Khan May 25 '15 at 10:55
  • Check this if it helps http://stackoverflow.com/questions/24029113/error-when-adding-input-view-to-textfield-ios-8 – Omer Waqas Khan May 25 '15 at 10:57
  • And this http://stackoverflow.com/questions/25865391/uiviewcontrollerhierarchyinconsistency-crashes-app-only-in-ios-8-and-xcode-6 – Omer Waqas Khan May 25 '15 at 10:59

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,153
  • 8
  • 12
0

Please check with below code -

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

Simply check if container view have superview

- (void)dismiss
{
  if ([containerView_ superview])
  {
    [containerView_ removeFromSuperview];
    containerView_ = nil;
    [super dismiss]; 
  }
}
Sudhin Davis
  • 2,010
  • 13
  • 18