为什么 UIIndicator 不移走?
我在我的应用程序中使用 UIActivityIndicator。我为它编写了如下代码:
-(void)startSpinner {
spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
spinner.hidden = NO;
spinner.frame = CGRectMake(137, 160, 50, 50);
[spinner setHidesWhenStopped:YES];
[self.view addSubview:spinner];
[self.view bringSubviewToFront:spinner];
[spinner startAnimating];
}
我在 UIButton 的操作事件上调用此方法,并删除指示器,我编写代码如下:
-(void)stopSpinner {
[spinner stopAnimating];
[spinner removeFromSuperview];
[spinner release];
}
单击按钮指示器出现,但当我在视图中调用 -(void)stopSpinner 方法时 willAppear 指示器不会消失。
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self stopSpinner];
}
即使我调试代码,我发现控制权也转到了 stopSpinner()
。
这里有什么问题呢?
I use UIActivityIndicator in my app. I have written code for it as follows:
-(void)startSpinner {
spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
spinner.hidden = NO;
spinner.frame = CGRectMake(137, 160, 50, 50);
[spinner setHidesWhenStopped:YES];
[self.view addSubview:spinner];
[self.view bringSubviewToFront:spinner];
[spinner startAnimating];
}
I call this method on the UIButton's action event, and to remove indicator I write the code as follows:
-(void)stopSpinner {
[spinner stopAnimating];
[spinner removeFromSuperview];
[spinner release];
}
on click on the button indicator appears but when I call -(void)stopSpinner method in view
willAppear the indicator does not disapppear.
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self stopSpinner];
}
Even I debug the code and I found that control also goes to the stopSpinner()
.
What is the problem here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
startSpinner
中可能存在潜在泄漏,因为您始终创建UIActivityIndicatorView
而不释放它。像这样更改您的方法:要停止动画,请为另一个 UIButton 操作分配
stopSpinner
。因为viewWillAppear
会在您点击任何按钮之前触发。附:也许你的意思是
viewWillDisappear
?You might have potential leak in
startSpinner
because you always createUIActivityIndicatorView
without releasing it. Change your method like this:For stopping animation assign
stopSpinner
for another UIButton action. CosviewWillAppear
will fired early then you tap on any button.ps. maybe you mean
viewWillDisappear
?