iphone - uiactivityindicatorview 不隐藏
我知道这是一个非常常见的问题,我阅读了 stackoverflow 中提出的大部分问题,但仍然不知道如何从视图中删除 uiactivityindicatorview 。 请在代码下面找到
@implementation FeedBackViewController
@synthesize m_activity,webView;
-(void)viewDidLoad{
[super viewDidLoad];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://equinox.library.pitt.edu/limesurvey/index.php?sid=87435&lang=en"]]];
}
- (void)dealloc {
[m_activity release];
[webView release];
[super dealloc];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
[m_activity stopAnimating];
[m_activity removeFromSuperview];
m_activity = nil;
}
- (void)webViewDidStartLoad:(UIWebView *)webView {
NSLog(@"in webViewDidFinishLoad")
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
m_activity.center = self.view.center;
[self.view addSubview: m_activity];
[m_activity startAnimating];
}
头文件
@interface FeedBackViewController : UIViewController<UIWebViewDelegate>{
IBOutlet UIWebView *webView;
IBOutlet UIActivityIndicatorView *m_activity;
}
@property (nonatomic, retain) IBOutlet UIWebView *webView;
@property (nonatomic, retain) UIActivityIndicatorView *m_activity;
另外,我已经选中了 IB 中的框,上面写着“停止时隐藏”。我将 NSLog(@"in webViewDidFinishLoad") 放在 webViewFinishLoad 方法中,似乎由于某种原因它没有命中该方法。 对于
NSLog(@"m_activity = %@",m_activity);
viewDidLoad 方法,它在控制台中给出如下消息
> m_activity = <UIActivityIndicatorView:
> 0x4d3d920; frame = (150 79; 20 20);
> hidden = YES; opaque = NO; autoresize
> = RM+BM; layer = <CALayer: 0x4d35ce0>>
i know this is a very common question, i read most of the questions asked in stackoverflow but still couldn't figure out how to remove the uiactivityindicatorview from the view.
please find below the code
@implementation FeedBackViewController
@synthesize m_activity,webView;
-(void)viewDidLoad{
[super viewDidLoad];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://equinox.library.pitt.edu/limesurvey/index.php?sid=87435&lang=en"]]];
}
- (void)dealloc {
[m_activity release];
[webView release];
[super dealloc];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
[m_activity stopAnimating];
[m_activity removeFromSuperview];
m_activity = nil;
}
- (void)webViewDidStartLoad:(UIWebView *)webView {
NSLog(@"in webViewDidFinishLoad")
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
m_activity.center = self.view.center;
[self.view addSubview: m_activity];
[m_activity startAnimating];
}
the header file
@interface FeedBackViewController : UIViewController<UIWebViewDelegate>{
IBOutlet UIWebView *webView;
IBOutlet UIActivityIndicatorView *m_activity;
}
@property (nonatomic, retain) IBOutlet UIWebView *webView;
@property (nonatomic, retain) UIActivityIndicatorView *m_activity;
Also, i have checked the box in the IB that says, hide when stopped. I put NSLog(@"in webViewDidFinishLoad")
in the webViewFinishLoad method, seems like it does not hit that method for some reason.
and for
NSLog(@"m_activity = %@",m_activity);
in the viewDidLoad method, it gives a message as below in the console
> m_activity = <UIActivityIndicatorView:
> 0x4d3d920; frame = (150 79; 20 20);
> hidden = YES; opaque = NO; autoresize
> = RM+BM; layer = <CALayer: 0x4d35ce0>>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的
webViewDidFinishLoad
函数可能没有被调用。如果web视图无法打开url,可能会发生这种情况。无论如何,您还应该实现webView:didFailLoadWithError:
方法并在那里停止活动指示器。-编辑-
要从 UIWebView 接收事件,您需要将控制器设置为 UIWebView 的委托。仅实现 UIWebViewDelegate 是不够的。您可以通过更新
viewDidLoad
方法来完成此操作,如下所示:Your
webViewDidFinishLoad
function is probably not being called. It may happen if the web view fails to open the url. In any case, you should also implementwebView:didFailLoadWithError:
method and stop the activity indicator there too.-edit-
To receive events from UIWebView you need to set the controller as the UIWebView's delegate. Just implementing the UIWebViewDelegate is not sufficient. You can do this by updating
viewDidLoad
method as follows:您应该将
NSLog(@"in webViewDidFinishLoad")
行添加到您的代码中,并观察控制台以查看代码是否达到这些点。由于这是一个非常简单的示例,也许 m_activity 没有连接到实际对象?尝试看看当您将其添加到 viewDidLoad 的末尾时是否获得地址或 null:NSLog(@"m_activity = %@",m_activity);
You should add
NSLog(@"in webViewDidFinishLoad")
lines to your code and watch the console to see if the code hits those points. Since this is a very simple example, perhaps m_activity is not connected to the actual object? Try to see if you get an address or a null when you add this to the end of your viewDidLoad:NSLog(@"m_activity = %@",m_activity);