0

I have what is quite a simple app at the moment that i am trying to get to load a url in a UIwebView. However all I get is a blank page and from what I can tell its just not trying to load the url at all.

I have posted the code i added from my .h and .m files below to let you guys see what is going on. It does actually load the web view just not the url.

Hope I have explained this ok.

Thanks

The .h file

@interface StaffsAirsoftAppViewController : UIViewController {

IBOutlet UIWebView *webView;
IBOutlet UIActivityIndicatorView *active;


}

The .m file

-(void)viewDidLoad {

[super viewDidLoad];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com"]]];
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(checkLoad) userInfo:nil repeats:YES];
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(checkNotLoad) userInfo:nil repeats:YES];


}

-(void)checkLoad {

if(webView.loading) {
    [active startAnimating];
}

}

-(void)checkNotLoad {
if(!(webView.loading)) {
    [active stopAnimating];



}

2 Answers 2

1

You should use the webview delegate methods for the same.

– webView:shouldStartLoadWithRequest:navigationType:
– webViewDidStartLoad:
– webViewDidFinishLoad:
Sign up to request clarification or add additional context in comments.

1 Comment

So i need to replace -(void)viewDidLoad, -(void)checkLoad and -(void)checkNotLoad with the above or am I getting that totally wrong as I suspect I am? Thanks for you help.
0

In addition to Preveen's suggestions for using the delegate, you could also check to verify that the UIWebView is visible on the screen. If you just create a UIWebView, but don't add it to the view hierarchy (either in code or in a nib file), then the user will never see it. This could also be a problem if you forgot to add your view controller's view as a subview of the app's window, for example.

A quick way to check this is to do:

webView.backgroundColor = [UIColor redColor];

in the viewDidLoad method. Now, even if the page doesn't load, you should be seeing red. If not, your view hierarchy is not set up correctly. One way to see what the view hierarchy actually is is to use code like this in your application delegate:

- (void)printViewHierarchy {
  NSLog(@"%@", [self.window recursiveDescription]);  // Ignore compiler warning.
}

// (inside your didFinishLaunching... method:
  [self performSelector:@selector(printViewHierarchy)
             withObject:nil
             afterDelay:1.0];

The reason for calling that method with delay 1.0 is to give the nib file a chance to load - they perform asynchronous loading, so if you print out the view hierarchy immediately, it will probably not be complete yet. After 1sec (less than that really) it will be set up, so you can rely on that printed-out value to see what your view hierarchy looks like.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.