UIActivityIndi​​cator没有显示 [英] UIActivityIndicator not showing up

查看:69
本文介绍了UIActivityIndi​​cator没有显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实现了一个UIActivityIndi​​cator,它显示在我程序的一部分中,而不显示在另一部分中.我在加载表格时会显示活动指示器,但是,在用户单击按钮并等待表格重新加载后,我试图让它重新开始制作动画.该表将重新加载,但没有指示器.这是代码.

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.

推荐答案

那是行不通的,因为动画仅在主应用程序循环正在运行"时显示.在您的代码中,您通过调用[self getSetDisplay]来阻塞主线程.

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].

您应该异步加载数据以使其工作(在后台线程中).然后,您可以调用 startAnimating ,启动线程,并在线程结束时停止动画.

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.

这篇关于UIActivityIndi​​cator没有显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆