0

this looks very simple, but I just can't figure out what's going wrong. So what I want to do is I have a button on the 1st controller, and when the user clicks that button, I push another controller into the navigation stack and show a website in the webview. code to push the webview controller:

SellerViewController *sellerController = [[SellerViewController alloc] initWithNibName:@"SellerViewController" bundle:nil];
[self.navigationController pushViewController:sellerController animated:YES];

code to load website

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.sellerWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.clickUrl]]];
}

I have a UIWebView in IB and I connect it to the outlet sellerWebView. I also checked the clickUrl, it is correct.The problem is when I click the button, the new controller shows up, but no content is loaded in the webview. Any suggestions? Thanks!

Fei Qu
  • 999
  • 2
  • 12
  • 26
  • 2
    Do you get any error messages? UIWebView's delegate has a method that informs about fails. Maybe this will help investigating. – Maciej Oczko Feb 04 '14 at 19:55
  • Could you share sample project? You'll get your answer much faster with it. – Vitaly S. Feb 04 '14 at 19:57
  • To expand on @MaciejOczko's comment: implement `UIWebViewDelegate` and see if you ever get a success or failure callback. Implementing `webView:shouldStartLoadWithRequest:navigationType:` should help you see if it even tries to load the page. – TotoroTotoro Feb 04 '14 at 20:04

1 Answers1

0

As others suggested, set a delegate and check for failure.

If your request does load and your issue is with the UIWebView's content, you can debug it, see this answer.

tl;dr:

If you're using iOS >= 6 and you have mountain lion (10.8) or Safari >= 6, you can just:

  1. Open the application in the simulator (or your device in XCode >= 4.5.x).
  2. Open Safari (go to Preferences -> Advanced and make sure "Show Develop Menu in Menubar" is on.
  3. From the Menu-bar (of Safari) select Develop -> iPhone Simulator -> [your webview page].

That's it !

Edit:

Glad you found the issue. You could use Safari to catch errors having to do with invalid or wrong URLs.

One you have attached the Web Inspector to your web view, click "Inspect" on the top bar, then click "Timelines" and "Network Requests", and try to load your request.

Since you left out the http:// before the path, it would likely get prefixed with file:// instead -- you'd be able to see that it is requesting the wrong resource without guesswork.

Community
  • 1
  • 1
Vasiliy Kulakov
  • 5,401
  • 1
  • 20
  • 15
  • Thank you guys, I added delegate and found the error. It's a stupid mistake, I forgot to add "http://" before url. Didn't find it by putting the url into browser, because browser added "http://" for me automatically. – Fei Qu Feb 04 '14 at 21:26