-1

I want to load a URL on a UIViewController with an UIWebView and UIActivityIndicatorView, but UIActivityIndicator never appears and UIWebView never loads the URL.

This is my code:

- (void) viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    self.title = @"Web";

    [self displayURL:[NSURL URLWithString:@"(Website)"]];
}

-(void) webViewDidFinishLoad:(UIWebView *)webView {
   [self.loadView stopAnimating];
   self.loadView.hidden = YES;
}

-(void) displayURL:(NSURL *) aURL {
    self.web.delegate = self;

    self.loadView.hidden = NO;
    [self.loadView startAnimating];

    [self.web loadRequest:[NSURLRequest requestWithURL:aURL]];
}
Saren Inden
  • 3,450
  • 4
  • 32
  • 45
Skurt
  • 11
  • 7

2 Answers2

0

If you add your webView by code, you need add

[self.view addSubview: web];

after you created webView, and of course you need to add UIActivityIndicatorView as a subView of webView or superView, so you need to add [web addSubview: loadView] or [self.view insertSubview: loadView aboveSubview: web];.

And about the URL, if your website URL is like www.google.com, you need to change @"(Website)" to the real URL. If your website is a file copied in your project, you need to change [NSURL URLWithString: ]; to [NSURL fileURLWithPath:[NSBundle mainBundle][pathForResource: ofType:]];.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • Just in case this is being built against iOS 9, you're going to want to make sure that the URL you are using is secured via SSL (e.g. 'https://www.google.com' and not 'http://www.google.com'). Otherwise nothing will load and iOS will complain. Another option would of course be to disable Application Transport Security for the URL or everything. But I just wanted to add this to be aware about it :) – Kilian Nov 14 '15 at 10:06
  • I really dont need to add webView because i have a .xib file with webView and UIActivityIndicator and " (website)" isnt on my code, the URL is the Apple Developer Program URL. Thanks u for the answer but i still have the same problem, anything happens when i start the app with webViewController – Skurt Nov 15 '15 at 11:44
  • Thanks for your help, i dont know whats the problem with my code – Skurt Nov 15 '15 at 11:44
0

Really poorly formulated question.

  • UIWebViewController does not work UIWebViewController does not exists, you are talking about a UIWebView in a UIViewController

  • Code is very incomplete

Saren Inden
  • 3,450
  • 4
  • 32
  • 45