Question

In my app, I have viewcontrollers that include webviews with activity indicators and they work fine. Now,in a new viewcontroller with a webview and activity indicator I am getting some weird behavior. In the simulator the view loads but the activity indicator remains spinning even when the view is finished loading. I copied everything exactly from another viewcontroller with webview and activity indicator that is working, but the weird behavior is still their. The URLs are just regular small html files so it's not like either one will take a long time to load. I don't know if this is a glitch in xcode (ver 5.0), or most likely something I am overlooking in the code. The code for the working viewcontroller is below:

#import "ProgramPDFViewController.h"

@interface ProgramPDFViewController ()

@end

@implementation ProgramPDFViewController
@synthesize webView;
@synthesize activity;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    [TestFlight passCheckpoint:@"PDFProgram-info-viewed"];

    UIBarButtonItem *backButtonItem = [[UIBarButtonItem alloc] initWithTitle:@" "    style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = backButtonItem;

    // Do any additional setup after loading the view.

    NSString *httpSource = @"<myURL>";
    NSURL *fullUrl = [NSURL URLWithString:httpSource];
    NSURLRequest *httpRequest = [NSURLRequest requestWithURL:fullUrl];
    [webView loadRequest:httpRequest];

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)webViewDidStartLoad:(UIWebView *)WebView
{
    [activity startAnimating];


}

-(void)webViewDidFinishLoad:(UIWebView *)WebView
{
    [activity stopAnimating];
    activity.hidden = TRUE;

}

@end

The code from the one with the weird behavior is below:

#import "ComitteeMeetingsViewController.h"

@interface ComitteeMeetingsViewController ()

@end

@implementation ComitteeMeetingsViewController
@synthesize webView, activity;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    [TestFlight passCheckpoint:@"CommitteMeetings-info-viewed"];

    UIBarButtonItem *backButtonItem = [[UIBarButtonItem alloc] initWithTitle:@" " style:UIBarButtonItemStylePlain target:nil action:nil];
    self.navigationItem.backBarButtonItem = backButtonItem;


    NSString *httpSource = @"<myOtherURL>";
    NSURL *fullUrl = [NSURL URLWithString:httpSource];
    NSURLRequest *httpRequest = [NSURLRequest requestWithURL:fullUrl];
    [webView loadRequest:httpRequest];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)webViewDidStartLoad:(UIWebView *)WebView
{
    [activity startAnimating];


}

-(void)webViewDidFinishLoad:(UIWebView *)WebView
{
    [activity stopAnimating];
    activity.hidden = TRUE;
}

@end
Was it helpful?

Solution

Are you sure the methods are actually called? Did you set the webView's delegate and included UIWebViewDelegate in the header file?

For troubleshooting: try adding

NSLog(@"webViewDidStartLoad");

and

NSLog(@"webViewDidFinishLoad"); 

to the corresponding methods and see if they show up in the log

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top