I’m new to this as I come from C++ and Perl background. Trying to learn from books but they are missing some core concepts of Objective-C. I need some help on this code to pull a webpage:
RootViewController.m
- (void)fetchWebsite:(NSString*)website{
NSLog(@"address: %@", website);
NSString *urlAddress = website;
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webImageDisplay loadRequest:requestObj];
[webImageDisplay release];
}
- (void)viewDidLoad {
[self fetchWebsite:@"website here"];
[super viewDidLoad];
}
This code works just fine but what I’m having trouble is calling this method from another class, like the code below:
I’m correctly calling the detail view controller from a 2nd view controller like this:
SubViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here. Create and push another view controller.
switch (indexPath.row) {
case 0: {
AnotherViewController *cViewController = [[AnotherViewController alloc] initWithNibName:@"AnotherViewController" bundle:nil];
cController.contentSizeForViewInPopover = CGSizeMake(320, 350);
[self.navigationController pushViewController:cViewController animated:YES];
[cViewController release];
break;
}
case 1: {
break;
}
}
}
Then I have a 3rd view controller that has the links to a new webpage which I want displayed on the webview. When I call the method here to access the function in RootViewController, it doesn’t seem to respond.
AnotherViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *itemRequested = [conusItems objectAtIndex:indexPath.row];
NSLog(@"logging: %@", itemRequested);
RootViewController *parent = [[RootViewController alloc] init];
[parent fetchWebsite:@"another website here"];
[itemRequested release];
}
I click on the button on the table view and I see the code is being called in the RootViewController with the NSLog but it doesn’t seem to display the new page. No errors or warnings, Any ideas? Thanks
If I may, you’re life will be easier and your application will be more flexible if you spin your web view out as it’s own view controller.
The real problem is you aren’t navigating to your web view controller (and you might not be initializing it correctly.)
Chances are the code will look more like this: