0

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

2 回答 2

3

您的webViewDidFinishLoad函数可能没有被调用。如果 web 视图无法打开 url,则可能会发生这种情况。无论如何,您还应该实现webView:didFailLoadWithError:方法并在那里停止活动指示器。

-编辑-

要从 UIWebView 接收事件,您需要将控制器设置为 UIWebView 的委托。仅仅实现 UIWebViewDelegate 是不够的。viewDidLoad您可以通过如下更新方法来做到这一点:

-(void)viewDidLoad{
 [super viewDidLoad];

 webView.delegate = self;
 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://equinox.library.pitt.edu/limesurvey/index.php?sid=87435&lang=en"]]];
}
于 2010-12-23T18:15:44.380 回答
0

您应该在代码中添加NSLog(@"in webViewDidFinishLoad")行并观察控制台以查看代码是否达到了这些点。由于这是一个非常简单的示例,也许 m_activity 没有连接到实际对象?当您将其添加到 viewDidLoad 的末尾时,请尝试查看是否获得了地址或 null:

NSLog(@"m_activity = %@",m_activity);

于 2010-12-23T19:43:35.777 回答