rahul
rahul

Reputation: 6487

iOS: Load UIWebView automatically

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];

Upvotes: 0

Views: 978

Answers (1)

user2436477
user2436477

Reputation:

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];

Upvotes: 4

Related Questions