我正在尝试创建一个自定义的类似警报的视图,该视图将在数据加载时显示,我还有一个取消按钮,以防加载时间过长。我在 ViewController 中创建它并将其作为子视图添加到窗口(不是 View Controller,因为我希望 Loading 警报视图尽可能地自行处理)。视图显示正常,但是当我单击按钮时,我收到一条“发送到已释放实例的消息”,我使用了 Zombie 工具,似乎所有保留它的东西都立即释放它(我正在使用 ARC)。
我注意到,如果我使用全局变量并将加载警报视图分配给它可以工作,但这不是预期的效果。我希望能够像 Alertview 一样显示它。这是我的“显示”功能,我该怎么做才能保留它自己(?)。
- (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];
}