removeFromSuperview ios崩溃

时间:2015-05-25 09:54:55

标签: ios objective-c iphone uiview

我的应用程序崩溃,并非总是如此,使用以下方法

// overridden
- (void)dismiss
{

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

崩溃发生在removerFromSuperview。

还有“show”方法

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

奇怪的是,代码曾经起作用。我正在尝试为arm64编译应用程序,但我不明白这种修改如何影响这些方法。

我的应用是非ARC应用,我现在不能去ARC。

有什么想法吗?

3 个答案:

答案 0 :(得分:0)

更改您的代码以解除此类视图。

//覆盖

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

   containerView_ = nil;
   [super dismiss]; 
}

答案 1 :(得分:0)

请查看以下代码 -

- (void)dismiss
{
  if (containerView_)
  {
    [containerView_ removeFromSuperview];
    containerView_ = nil;
    [super dismiss]; 
  }
}

答案 2 :(得分:0)

只需检查容器视图是否具有超级视图

- (void)dismiss
{
  if ([containerView_ superview])
  {
    [containerView_ removeFromSuperview];
    containerView_ = nil;
    [super dismiss]; 
  }
}
相关问题