我正在尝试使用按钮向窗口视图添加子视图,但子视图上的按钮正在发送已释放的实例

时间:2013-04-19 13:29:38

标签: ios objective-c subviews

我正在尝试创建一个自定义的类似警报的视图,在数据加载时显示,我还有一个取消按钮,以防加载时间过长。我在ViewController中创建它并将其作为子视图添加到窗口(而不是View Controller,因为我希望Loading alert视图尽可能地处理它自己)。视图显示正常,但当我点击按钮时,我收到一条'消息发送到解除分配的实例'我使用了Zombie工具,看来保留它的所有内容都是立即释放它(我正在使用ARC)。

我注意到如果我使用全局变量并将我的加载警报视图分配给它可以工作,但这不是所需的效果。我希望能够像Alertview一样展示它。这是我的'show'函数,我可以做什么使它保留自己(?)。

    - (void) show{

    //this is so the user can't accidentally hit a button in the parent view while the
    // alert is active
    parentView.view.userInteractionEnabled = NO;

    //I get the window
    id appDelegate = [[UIApplication sharedApplication] delegate];
    UIWindow *window = [appDelegate window];

    //I set up the view and create/assign the correct placement of it as well as 
    //make it invisible so I can fade it in later.
    self.view.alpha = 0.0;
    self.view.frame = [self createFrameFor:self.view withOffset:0];

    //since the view is smaller that the window I create an image that is the size 
    //of the window but semi-transparent
    UIImage *bg = [self setupBackground];
    backgroundView = [[UIImageView alloc] initWithImage:bg];
    backgroundView.alpha = 0.7;

    //I add the views to the window here
    [window addSubview:backgroundView];
    [window addSubview:self.view];

    [activityIndicator startAnimating];

    [self fadeIn:self.view];
    }

0 个答案:

没有答案