UIActivityIndicator 未显示
我已经实现了一个 UIActivityIndicator,它显示在我的程序的一部分中,但没有显示在另一部分中。我在加载表格时出现了活动指示器,但是,我试图让它在用户单击按钮并等待表格重新加载后再次开始动画。表重新加载,但没有指示器。这是代码。
- (void)viewWillAppear:(BOOL)animated {
CGRect frame = CGRectMake (120.0, 185.0, 80, 80);
activity = [[UIActivityIndicatorView alloc] initWithFrame: frame];
activity.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
[activity startAnimating];
[navigationUpdateFromDetail.window addSubview: activity];
[super viewWillAppear:animated];
}
它出现在那个部分。然而,对于下一部分,它似乎不想出现。
- (IBAction) btnGreaterTen_clicked :(id)sender {
self.searchDistance = [NSNumber numberWithDouble : 10];
CGRect frame = CGRectMake (120.0, 185.0, 80, 80);
activity = [[UIActivityIndicatorView alloc] initWithFrame: frame];
activity.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
[navigationUpdateFromDetail.window addSubview: activity];
[activity startAnimating];
NSLog(@" search value after change %@", [searchDistance description]);
[self getSetDisplay];
[activity stopAnimating];
}
该按钮更改了一个变量,并且应该启动动画,但它没有。我改变了颜色以确保它不只是混合在一起,所以这不是解决方案。我尝试重新创建相同的对象,但仍然没有成功。 先感谢您。
I have implemented a UIActivityIndicator that shows up in one part of my program but not another. I have the activity indicator come up while i am loading a table, however, i am trying to get it to start animating again after the user has clicked a button and is waiting for the table to reload. The table reloads, but no indicator. Here is the code.
- (void)viewWillAppear:(BOOL)animated {
CGRect frame = CGRectMake (120.0, 185.0, 80, 80);
activity = [[UIActivityIndicatorView alloc] initWithFrame: frame];
activity.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
[activity startAnimating];
[navigationUpdateFromDetail.window addSubview: activity];
[super viewWillAppear:animated];
}
It comes up for that part. However, for the next part it does not want to seem to come up.
- (IBAction) btnGreaterTen_clicked :(id)sender {
self.searchDistance = [NSNumber numberWithDouble : 10];
CGRect frame = CGRectMake (120.0, 185.0, 80, 80);
activity = [[UIActivityIndicatorView alloc] initWithFrame: frame];
activity.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
[navigationUpdateFromDetail.window addSubview: activity];
[activity startAnimating];
NSLog(@" search value after change %@", [searchDistance description]);
[self getSetDisplay];
[activity stopAnimating];
}
That button changes a variable and is suppose to start the animation, but it does not. I have changed the color to make sure it was not just blending in, so that is not the solution. I tried to recreate the same object, but still no luck.
Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是行不通的,因为动画只会在主应用程序循环“运行”时显示。在您的代码中,您通过调用 [self getSetDisplay] 来阻塞主线程。
您应该异步加载数据才能使其工作(在后台线程中)。然后,您可以调用 startAnimating,启动线程,并在线程结束时停止动画。
That won't work, because the animation will only show when the main application loop is "running". In your code, you're blocking the main thread by calling [self getSetDisplay].
You should load your data asynchronously to make this work (in a background thread). Then you can call startAnimating, start your thread, and when the thread finishes, stop the animation.
这已经困扰我很多年了,我刚刚发现,当使用搜索显示控制器时,我必须将活动指示器添加为搜索结果的子视图才能显示它。在我的 viewDidLoad 中,我放...
当我想开始动画时,我放...
希望这对某人有帮助。
This has been bugging me for ages, and I just found that when using a search display controller I had to add the activity indicator as a subview of the search results to get it to show. In my viewDidLoad, I put...
When I want to start animating, i put...
Hope this helps someone.
尝试
在之前添加
try adding
just before