【问题标题】:Activity indicator in a UITabBar application on the iPhoneiPhone 上的 UITabBar 应用程序中的活动指示器
【发布时间】:2009-07-10 12:54:04
【问题描述】:

我有一个 UITabBar + UINavigationController 应用程序,它经常需要来自互联网的数据。有时它需要很长时间才能得到它,所以我想显示一个活动指示器。

我正在尝试在我的 applicationDidFinishLaunching 方法中向我的窗口添加一个 activityView:

[window addSubview:tabBarController.view];
fullscreenLoadingView.hidden = YES;
[window addSubview:fullscreenLoadingView];

然后我将应用程序委托作为观察者添加到默认通知中心:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(startFullscreenLoading:) name:@"startFullscreenLoading" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(stopFullscreenLoading:) name:@"stopFullscreenLoading" object:nil];

并实现方法:

- (void)startFullscreenLoading:(NSNotification *)notification {
    fullscreenLoadingView.hidden = NO;
}

- (void)stopFullscreenLoading:(NSNotification *)notification {
    fullscreenLoadingView.hidden = YES;
}

当我直接在 applicationDidFinishLaunching 方法中使用它时,加载指示器视图按预期显示 upp:

[[NSNotificationCenter defaultCenter] postNotificationName:@"startFullscreenLoading" object:self];

但是当我从其中一个导航控制器中使用它时,会调用 startFullscreenLoading: 方法,但我看不到加载指示器视图。这是为什么呢?

【问题讨论】:

    标签: iphone cocoa-touch


    【解决方案1】:

    您是否在后台线程上加载数据?您的主线程将被阻止并且无法重绘或处理任何其他事件。

    【讨论】:

    • 好的,我明白了,不,我是在主线程中加载它,我认为主线程会首先发送通知并调整方法,然后再进行数据加载。但是好的,我明白了,我尝试在另一个线程中加载它。
    • 谢谢,这是我的问题,现在已经解决了 :-)
    【解决方案2】:

    我能猜到的最有可能的是,您的指标视图低于其他视图。试试

    [[fullScreenLoadingView superView] bringSubviewToFront:fullScreenLoadingView]

    如果这不起作用,我建议闯入-startFullscreenLoading 以确保fullscreenLoadingView 仍然有效。

    【讨论】:

    • 我都试过了,NSLog(@"%@", fullScreenLoadingView);说它是一个 > 和 [window subviews] 包含两个视图。
    【解决方案3】:

    在我的应用程序中,我通过在 IB 中添加 UIActivityView 并确保它高于一切(作为顶级对象)来做到这一点。它设置为停止时不可见。

    然后在我的代码中,我用 [activityIndi​​cator startAnimating] 让它出现并用 [activityIndi​​cator stopAnimating] 让它消失;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多