Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have two viewControllers. In my first viewController I prepare a web address and as soon as I hit a button the second view controller should open the address in a web view. I am not sure how to load the webView automatically with the address. I mean, I am not sure where to call loadRequest in the second view controller. I cannot call in the viewDidLoad as the address will not be sent by then.

WebViewController *webViewController = [[WebViewController alloc] initWithNibName:@"WebViewController" bundle:nil];
webViewController.query = [self getQuery:[query text]];
UINavigationController *navController = [[UINavigationController alloc]
                                         initWithRootViewController:webViewController];

// [navController pushViewController:subView animated:YES];
[[navController navigationBar] setHidden:YES];
[navController setToolbarHidden:YES];
[navController setModalPresentationStyle:UIModalPresentationCurrentContext];
[self presentViewController:navController animated:YES completion:nil];
share|improve this question
    
viewWillAppear? and also if you know the url why don't just have an initializer to wich you can pass directly the url, and start the request in viewDidLoad? –  elio.d Jun 12 '13 at 21:38

1 Answer 1

you can write this in viewWillAppear of second view controller

UIViewController *webViewController = [[UIViewController alloc]init];

UIWebView *webView = [[UIWebView alloc]initWithFrame:CGRectMake(0,0,320,480)];
webView.scalesPageToFit= YES;
NSString *url;
url =[NSString stringWithFormat:@"www.google.com"];
NSURL *nsurl = [NSURL URLWithString:url];

NSURLRequest *nsrequest = [NSURLRequest requestWithURL:nsurl];
[webView loadRequest:nsrequest];
[webViewController.view addSubview:webView];
[self.navigationController pushViewController:webViewController  animated:YES];
share|improve this answer
    
accept this answer if this helped. –  user2436477 Jan 2 at 13:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.