Update
Fixed the loading issue. As I was using a custom cell class I had only set the identifier of the tableview cell in storyboard to the name of the customcell, not the actual class itself! Rookie mistake, sorry!
This fixes the lack of loading the webpage in the viewDidLoad method. Now I just need to sort it so it’ll load the correct webpage depending on the table row choice. Is PrepareForSegue ideal for this? Thanks
Original Post
In my app I have FirstViewController with a tableview which lists objects that then load webviews in the secondviewcontroller when opened.
So in my didSelectRowAtIndexPath method I currently have:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{ [self performSegueWithIdentifier:@"Detail" sender:self];
NSIndexPath *selectedRowIndex = [self.tableView indexPathForSelectedRow];
DetailViewController *detailViewController = [DetailViewController alloc];
detailViewController.urlToGet = @"www.google.com"
}
Now DetailViewController of course has its viewcontroller object in Storyboard where the delegate and webView outlet are set.
In the DetailViewController class itself I even tried this in viewDidLoad just to get some website showing:
NSString *fullURL = @"http://www.google.com";
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
But all I get is a blank webview.
I tried a tutorial with a new project which worked fine and then copied it – sadly it does not work here at the moment.
I also tried prepareForSegue (as that would get the information across) but this did not work.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
/*
When a row is selected, the segue creates the detail view controller as the destination.
Set the detail view controller's detail item to the item associated with the selected row.
*/
if ([[segue identifier] isEqualToString:@"Detail"]) {
DetailViewController *detailViewController = [segue destinationViewController];
detailViewController.urlToGet = @"www.google.com";
}
}
With the segue between the two ViewControllers having an identifier of Detail.
Any idea why I can’t get the object to even load the website specified in its viewDidLoad?
thanks
Fixed it! I was using a custom cell class I had only set the identifier of the tableview cell in storyboard to the name of the customcell, not the actual class itself! Rookie mistake, sorry!