Search code examples
objective-cuiwebviewxcode6.1ios8.1

UIWebView shows black screen without data


iOS 8.1, XCode 6.1, Storyboards and 2 UIViewControllers that look like this:

enter image description here The view on the left is the main view, the view on the right is a UIWebView that will show help information written in HTML. My problem is that when I tap on the blue circle with an 'i' in it, it is supposed to go to the 2nd view controller (which it does) and display the html for that language (which it doesn't do)... all I get is a black screen! Here is my code to display the html file contents:

-(void) viewWillAppear:(BOOL)animated  {

NSURL *indexURL;
NSString *sysLangCode = [[NSLocale preferredLanguages] objectAtIndex:0];

//  do we support this language?
if([sysLangCode isEqualToString:@"en"] || [sysLangCode isEqualToString:@"de"] || [sysLangCode isEqualToString:@"it"] ||
   [sysLangCode isEqualToString:@"es"] || [sysLangCode isEqualToString:@"fr"] || [sysLangCode isEqualToString:@"ja"] ||
   [sysLangCode isEqualToString:@"zh-Hant"] )  {

    indexURL = [[NSBundle mainBundle] URLForResource: [NSString stringWithFormat:@"instRST-%@", sysLangCode]
                                       withExtension:@"html"];   //  contatenate the language code to the filename
}
else
    indexURL = [[NSBundle mainBundle] URLForResource: @"instRST-en" withExtension:@"html"];  //  make 'en' the default

NSLog(@"\n\nmainBundle: %@",[NSBundle mainBundle]);

NSURLRequest *request = [NSURLRequest requestWithURL: indexURL];

NSLog(@"\n\nhtmlURL: %@",indexURL);

[self.webView loadRequest:request];

}


- (void)viewDidLoad  {

[super viewDidLoad];

[webView setDelegate:self];
}


- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error  {

NSLog(@"Failed to load with error :%@",[error debugDescription]);

}

UPDATE This is the connection for the webView:

enter image description here

I have tried different scenarios for hours now, and have given up doing this on my own. Can someone please tell me what I'm doing wrong?


Solution

  • Since you are using a storyboard you must use a Segue to present your ViewController. Delete your button action implementation and Control+Drag from your button onto your Help view controller. Link it to the Show segue.