UIActivityIndi​​cator 未显示

发布于 2024-08-16 15:52:59 字数 1227 浏览 8 评论 0原文

我已经实现了一个 UIActivityIndi​​cator,它显示在我的程序的一部分中,但没有显示在另一部分中。我在加载表格时出现了活动指示器,但是,我试图让它在用户单击按钮并等待表格重新加载后再次开始动画。表重新加载,但没有指示器。这是代码。

- (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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

风蛊 2024-08-23 15:52:59

这是行不通的,因为动画只会在主应用程序循环“运行”时显示。在您的代码中,您通过调用 [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.

扭转时空 2024-08-23 15:52:59

这已经困扰我很多年了,我刚刚发现,当使用搜索显示控制器时,我必须将活动指示器添加为搜索结果的子视图才能显示它。在我的 viewDidLoad 中,我放...

// create activity indicator
activityIndicator = [[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(0.0f, 0.0f, 32.0f, 32.0f)];
[activityIndicator setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleGray];
[self.searchDisplayController.searchResultsTableView addSubview:activityIndicator];

当我想开始动画时,我放...

[activityIndicator setCenter:CGPointMake(self.searchDisplayController.searchResultsTableView.frame.size.width/2.0f, self.searchDisplayController.searchResultsTableView.frame.size.height/2.0f)];
[activityIndicator startAnimating];

希望这对某人有帮助。

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

// create activity indicator
activityIndicator = [[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(0.0f, 0.0f, 32.0f, 32.0f)];
[activityIndicator setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleGray];
[self.searchDisplayController.searchResultsTableView addSubview:activityIndicator];

When I want to start animating, i put...

[activityIndicator setCenter:CGPointMake(self.searchDisplayController.searchResultsTableView.frame.size.width/2.0f, self.searchDisplayController.searchResultsTableView.frame.size.height/2.0f)];
[activityIndicator startAnimating];

Hope this helps someone.

要走就滚别墨迹 2024-08-23 15:52:59

尝试

activity.hidden = NO;

在之前添加

[activity startAnimating];

try adding

activity.hidden = NO;

just before

[activity startAnimating];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文