xcode UIActivityIndi​​catorView 没有消失

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6555801/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 21:23:51  来源:igfitidea点击:

UIActivityIndicatorView Not disappearing

iphoneobjective-cxcodeinterface-builderuiactivityindicatorview

提问by Paul Morris

This seems to be a very simplistic issue, but I literally cannot get it working.

这似乎是一个非常简单的问题,但我确实无法让它发挥作用。

I have a section of my app which takes my user to a WebView displaying my site. As part of the built in 'browser' experience i want a UIActivityIndicator located to let the user know that the site is loading. Obviously when this is done i want the indicator to disappear.

我的应用程序的一部分将我的用户带到显示我的网站的 WebView。作为内置“浏览器”体验的一部分,我想要一个 UIActivityIndi​​cator 来让用户知道网站正在加载。显然,当这完成后,我希望指标消失。

At the minute, the activity indicator animates, but then keeps animating forever and does not stop or disappear.

在这一分钟,活动指示器动画,但随后永远保持动画并且不会停止或消失。

The code I am using in .h is as follows;

我在 .h 中使用的代码如下;

@interface AppSupportWebsite : UIViewController <UIWebViewDelegate> {

    IBOutlet UIActivityIndicatorView *activityIndicator;

}

@property (nonatomic, retain) UIActivityIndicatorView *activityIndicator;

@end

And within my .m file I have the following; (abbreviated to just show the activity indicator specific code)

在我的 .m 文件中,我有以下内容;(缩写为仅显示活动指示器特定代码)

@synthesize activityIndicator;


- (void)webViewDidStartLoad:(UIWebView *)webView {
    [activityIndicator startAnimating];

}

- (void)webViewDidFinishLoad:(UIWebView *)webView {
    [activityIndicator stopAnimating];
}

I have created an activity indicator within Interface Builder and through Files Owner connected the activityIndicator IBOutlet to the white activity indicator through IB but it just wont disappear.

我在 Interface Builder 中创建了一个活动指示器,并通过 Files Owner 将活动指示器 IBOutlet 通过 IB 连接到白色活动指示器,但它不会消失。

回答by Vijay-Apple-Dev.blogspot.com

select ur activity indicator then

选择你的活动指示器然后

cmd+1

指令+1

select "hide when stopped"

选择“停止时隐藏”

check ur webview.delegate=self;

检查你的 webview.delegate=self;

- (void)webViewDidFinishLoad:(UIWebView *)webView {

    NSLog(@"finished");

    [self.activityIndicator stopAnimating];

}

回答by adimitri

This is just a stab in the dark, but you may be having issues because the UIWebView Delegate is being called from a different thread other than the main thread. So you may be getting some race conditions as a result.

这只是黑暗中的一个小插曲,但您可能会遇到问题,因为 UIWebView 委托是从主线程以外的不同线程调用的。因此,您可能会遇到一些竞争条件。

Give this Grand Central Dispatch Code (GCD) a try and let me know if that works:

试试这个 Grand Central Dispatch Code (GCD),让我知道它是否有效:

- (void)webViewDidFinishLoad:(UIWebView *)webView {
    dispatch_async(dispatch_get_main_queue(), ^(void) {
      [activityIndicator stopAnimating];
    });
}

回答by Deeps

- (void)webViewDidStartLoad:(UIWebView *)webView {
    [activityIndicator startAnimating];
}

It is possible to run above code multiple time it your website have multiple redirects. so I would not suggest to put this line in this delegate method. I would suggest to put this in viewWillAppear delegate method of viewController.

如果您的网站有多个重定向,则可以多次运行以上代码。所以我不建议将此行放在此委托方法中。我建议把它放在 viewController 的 viewWillAppear 委托方法中。

-(void)viewWillAppear:(BOOL)animated{
   [activityIndicator startAnimating];
}

Also, make sure you bind UIActivityIndicator in your xib.

另外,请确保在您的 xib 中绑定 UIActivityIndi​​cator。

Hope this help.

希望这有帮助。

回答by xianritchie

Can you add an NSLog statement (just something like NSLog(@"Web Finished Loading!");) to the webViewDidFinishLoad method? My guess is that this method is not being called. There could be a few reasons for that. For instance, if you are releasing the webView before you hit the method, it might not call the method at all.

你能在 webViewDidFinishLoad 方法中添加一个 NSLog 语句(就像 NSLog(@"Web Finished Loading!");)吗?我的猜测是这个方法没有被调用。这可能有几个原因。例如,如果您在点击该方法之前释放 webView,它可能根本不会调用该方法。