title: iOS Load Web Page in UIWebView from Another View Controller
body: <p>I have a tabbed application, with a tab that contains a UIWebView and a second tab with a Table View Controller.</p>
  
  <p>I'm trying to make it so that when I click on a row in the table it takes me to my other tab and loads a web page.</p>
  
  <p>Here's my storyboard:
  <img src="https://i.stack.imgur.com/z5KPR.png" alt="My Storyboard"></p>
  
  <p>This is in my implementation for the web view:</p>
  
  <pre><code>-(void)loadAViewer:(NSURL*)viewerURL
  {
      NSURLRequest *requestObj = [NSURLRequest requestWithURL:viewerURL];
      [sfnViewer loadRequest:requestObj];
  }
  </code></pre>
  
  <p>And then in the table view controller:</p>
  
  <pre><code>- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  {
      //Get the URL from plist
      ...
  
      //Generate url, pass it in and switch to web view tab
      viewerURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@/viewer?username=%@&amp;pw=%@&amp;%@", web, loc, user, pass, params]];
  
      ViewerFirstViewController *viewerWebView = [[ViewerFirstViewController alloc] init];
      [viewerWebView loadAViewer:viewerURL];
  
      [tableView deselectRowAtIndexPath:indexPath animated:YES];
      [self.tabBarController setSelectedIndex:0];
  
  }
  </code></pre>
  
  <p>Currently nothing happens. I'm taken to the other tab but with a blank UIWebView - no page loads but it doesn't crash either.</p>
  
  <p>//Edit - Changes made based on answer from Steve</p>
  
  <p>Based on this I've added
      @property (strong, nonatomic) NSURL viewerUrl;
  in my .h file for the UIWebView tab.</p>
  
  <p>I've synthesized it in the .m and added this to my viewDidLoad method.</p>
  
  <pre><code>NSURLRequest *requestObj = [NSURLRequest requestWithURL:viewerURL];
  [sfnViewer loadRequest:requestObj];
  </code></pre>
  
  <p>In the Table View Controller I'm now doing this.</p>
  
  <pre><code>- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  {
      //Get the URL from plist
      ...
  
      //Generate url, pass it in and switch to web view tab
      viewerURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@/viewer?username=%@&amp;pw=%@&amp;%@", web, loc, user, pass, params]];
  
      ViewerFirstViewController *viewerWebView = [[ViewerFirstViewController alloc] init];
      [viewerWebView setViewerUrl:viewerURL];
  
      [tableView deselectRowAtIndexPath:indexPath animated:YES];
      [self.tabBarController setSelectedIndex:0];
  
  }
  </code></pre>
  
  <p>Still to no avail.</p>