Question

Sorry if this is an easy one. Basically, here is my code:

MainViewController.h:

#import "FlipsideViewController.h"

@interface MainViewController : UIViewController <UIWebViewDelegate, FlipsideViewControllerDelegate> {
    IBOutlet UIWebView *webView;
    IBOutlet UIActivityIndicatorView *spinner;
}

- (IBAction)showInfo;

@property(nonatomic,retain) UIWebView *webView;
@property(nonatomic,retain) UIActivityIndicatorView *spinner;

@end

MainViewController.m:

#import "MainViewController.h"
#import "MainView.h"

@implementation MainViewController

@synthesize webView;
@synthesize spinner;

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

 - (void)viewDidLoad {

     NSURL *siteURL;
     NSString *siteURLString;

     siteURLString=[[NSString alloc] initWithString:@"http://www.site.com"];

     siteURL=[[NSURL alloc] initWithString:siteURLString];

     [webView loadRequest:[NSURLRequest requestWithURL:siteURL]];

     [siteURL release];
     [siteURLString release];

 [super viewDidLoad];
 }

- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller {

    [self dismissModalViewControllerAnimated:YES];
}

- (void)webViewDidFinishLoad:(UIWebView *)webView {
    [spinner stopAnimating];  
    spinner.hidden=FALSE;
    NSLog(@"viewDidFinishLoad went through nicely");
}

- (void)webViewDidStartLoad:(UIWebView *)webView {     
    [spinner startAnimating];     
    spinner.hidden=FALSE;
    NSLog(@"viewDidStartLoad seems to be working");
}

- (IBAction)showInfo {    

    FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:@"FlipsideView" bundle:nil];
    controller.delegate = self;

    controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentModalViewController:controller animated:YES];

    [controller release];
}

- (void)dealloc {
    [spinner release];
    [webView release];
    [super dealloc];
}


@end

Unfortunately nothing is ever written to my log, and for some reason the UIActivityIndicator never seems to appear. What's going wrong here?

Thanks folks

Jack

Was it helpful?

Solution

You need to set the UIWebView delegate. You implement the protocol but you never tell the UIWebView that this class is the delegate so those methods will never be called.

webView.delegate = self;

Also, you may want to check out this question/answer on how to implement the UIWebViewDelegate methods.

OTHER TIPS

- webViewDidFinishLoad: is sent to the Web View's delegate when it has successfully loaded content from the URL in question. Have you confirmed that the URL is valid by checking it in Safari? Have you double checked your delegate connection?

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