0

I can't seem to find much on the net that is specific to my question.

Here's my situation; I have a Table View Controller with 5 cells that act purely as buttons that correspond to particular web sites, and each button will push to a View Controller with a web view on it, displaying the corresponding website.

Instead of having 5 different view controllers all with their own web view on it, is there some way to programatically determine which table cell was clicked so that I can change the URL in which the Web View references? That way I only need one View Controller and one Web View, and depending on the particular cell that was selected it will display a different website in that Web View. How might I do this? I just feel like it is redundant to have 5 very similar view controllers.

See below for my current code and some screen shots.

This code simply loads the URL into the web View (Websites.m)

NSURL *cpaURL = [NSURL URLWithString:@"http://www.cpagroup.com.au"];  // Define new URL variable
NSURLRequest *myRequest = [NSURLRequest requestWithURL:cpaURL];  // Define new web page request
[cpaWebView loadRequest:myRequest];  // Load request to page
cpaWebView.scalesPageToFit = YES;  // Scale page to fit on the screen

Link between table and one web view

Table and Web View Link

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
n00bAppDev
  • 610
  • 3
  • 10
  • 21

1 Answers1

1

Just pass the NSURL string into the webSite file (Check here for passing data), In your didSelectRow .

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
  // initialise your website class file
   websiteObj.urlString = // Use the Array OR something which you had reference of cell data
}

And in your website class, use the urlString to load the webView

Community
  • 1
  • 1
Kumar KL
  • 15,315
  • 9
  • 38
  • 60
  • Ahhh you legend that helped with heaps. Thank you, and sorry for not finding that link before hand, I mustn't have been searching for the right thing :) – n00bAppDev Aug 01 '14 at 07:33