简体   繁体   English

iOS:自动加载UIWebView

[英]iOS: Load UIWebView automatically

I have two viewControllers. 我有两个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. 在我的第一个viewController中,我准备了一个网址,当我按下按钮时,第二个视图控制器应在一个Web视图中打开该地址。 I am not sure how to load the webView automatically with the address. 我不确定如何使用该地址自动加载webView。 I mean, I am not sure where to call loadRequest in the second view controller. 我的意思是,我不确定在第二个视图控制器中在哪里调用loadRequest。 I cannot call in the viewDidLoad as the address will not be sent by then. 我无法在viewDidLoad中调用,因为届时地址将不会发送。

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

you can write this in viewWillAppear of second view controller 您可以在第二个视图控制器的viewWillAppear中编写此代码

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM