I am quite new to UITableViewController, I would like to make a static cells UITableViewController and each static cells open up the same nib file but the URL of the UIWebView will be different. e.g. row 1 will open google.com and row 2 in yahoo.com. May I know how can i do that?
Thanks
You'll want to implement the tableview delegate method, tableView:didSelectRowAtIndexPath:
, this will allow you to ask the tableview which cell was selected and then take the appropriate action. An example would be:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if ([cell.textLabel.text isEqualToString:@"google"]) {
// open google
} else if ([cell.textLabel.text isEqualToString:@"yahoo"]) {
// open yahoo
}
}
EDIT TO ANSWER THE QUESTION ASKED IN COMMENTS
You didn't state this, but from reading your question, I'm guessing you are using separate nib files and want to push another view controller on screen that controls a web view when the user selects one of the static cells. The steps to do this are to:
- Create the new VC
- Give the public property the URL you want to load
- Push the VC on screen
in code that will look something like:
WebViewController webVC = [[WebViewController alloc] initWithNibName:@"your nib name" bundle:[NSBundle mainBundle]];
webVC.url = // some NSURL object, or maybe just a string that has the URL - that's up to you
[self.navigationController pushViewController:webVC animated:YES]