-1

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?

SpokaneDude
  • 4,856
  • 13
  • 64
  • 120
  • Are any delegate methods called? Have you logged the web view property? You're missing some calls to super though that shouldn't be terminal. – Wain Feb 23 '15 at 22:12
  • Ahhh... .the "webView" property is nil!! How can that be? – SpokaneDude Feb 23 '15 at 22:25
  • Put **[super viewWillAppear:animated]** at the top of the viewWillAppear method. Does anything change? – Chase Feb 23 '15 at 22:31
  • @Chase no, no change... also, I have updated the question with an image of the connection for the webView. – SpokaneDude Feb 23 '15 at 22:34
  • Can you show me the IBAction method for your button that pushes the Help View Controller onto the screen? – Chase Feb 23 '15 at 22:43
  • `- (IBAction)bDisplayHelp:(UIButton *)sender { HelpViewController *hvc = [HelpViewController new]; [self presentViewController: hvc animated:YES completion: nil]; }` And by the way, webView is nil, from beginning to end! – SpokaneDude Feb 23 '15 at 22:47
  • Well really quickly, since you said you were using the storyboard... you should be using a Segue instead of presenting your view controller programatically. – Chase Feb 23 '15 at 22:53
  • Delete the button action implementation and Control+Drag from your button onto your Help view controller. Link it to the **Show** segue. Tell me if the view is still black after you do this. – Chase Feb 23 '15 at 22:54
  • **OMG!** Please re-write your *comment* as the answer so I can give you points... (wonder why this wasn't mentioned anywhere in SO or Google that I could find?) It's working just fine now... one more Q: how do I return to the calling view now that I'm using a segue (a document url would be very helpful)? – SpokaneDude Feb 23 '15 at 22:58
  • To go back you can make a back button and simply do the same control + drag option in reverse back to your original view controller. Here is a good guide on how to "unwind" your Segues http://developer.xamarin.com/recipes/ios/general/storyboard/unwind_segue/ – Chase Feb 23 '15 at 23:03

2 Answers2

1

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.

Chase
  • 2,206
  • 1
  • 13
  • 17
  • It doesn't need to be a segue, but the controller needs to be created from the storyboard in some way... – Wain Feb 24 '15 at 07:33
0

i also face the same issue, below webview property helps me to avoid black screen problem
[self.web setOpaque:NO];