Note that there are some explanatory texts on larger screens.

plurals
  1. POiPad iPhone: Calling Webview from anther View Controller class
    text
    copied!<p>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:</p> <p><strong>RootViewController.m</strong></p> <pre><code> - (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]; } </code></pre> <p>This code works just fine but what I'm having trouble is calling this method from another class, like the code below:</p> <p>I'm correctly calling the detail view controller from a 2nd view controller like this:</p> <p><strong>SubViewController.m</strong></p> <pre><code>- (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; } } } </code></pre> <p>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.</p> <p><strong>AnotherViewController.m</strong></p> <pre><code>- (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]; } </code></pre> <p>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 </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload