You pop the view on button click.write.So on first view controller write the method of loadWebView
in viewWillAppear instead of viewWillLoad.And in secondController why are you allocating a new controller object and pop the previous view controller.No need to allocate and load.Simply pop the view.
How to load uiwebview from another view controller
-
26-06-2022 - |
Pregunta
I have a uiwebview in first viewcontroller,and i have an uibutton on secondview controller,when i click uibutton i am changing load request. The thing is ,the url is changed but webview didnt reload.
FirstViewController
-(void)viewDidLoad
{
a=@"http://www.google.com";
[self loadWebview];
}
-(void)loadWebview
{
a=[[NSUserDefaults standardUserDefaults]objectForKey:@"key"];
NSLog(@"current URL:%@",a);
self.myweb.delegate=self;
[self.myweb loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:a]]];
}
- (IBAction)goSecond:(id)sender
{
SecondViewController *vv=[[SecondViewController alloc]init];
[self.navigationController pushViewController:vv animated:YES];
}
SecondViewController
- (IBAction)goFirst:(id)sender {
NSString* b=@"http://www.apple.com";
[[NSUserDefaults standardUserDefaults] setObject:b forKey:@"key"];
FirstViewController *vv=[[FirstViewController alloc]init];
[vv loadWebview];
[self.navigationController popViewControllerAnimated:YES];
}
Result is:
current URL:http://www.google.com
current URL:http://www.apple.com
But webview didn't load,i want to load www.apple.com.Thanks in advance
Solución
Otros consejos
You are in second view controller and calling the loading the method of first view controller.And WebView as subview of first view controller.So you need to push your first view controller to see the effect.In second view controller you can't see what is happening on your first.
first of all you pass ur link two another view controller//
your first view coding like this
- (IBAction)goFirst:(id)sender
{
secondview *video=[[secondview
alloc] initWithNibName:@"secondview" bundle:nil];
video.videourl=@"http://www.google.com";
[self.navigationController pushViewController:video animated:YES];
[video release];
}
secondview controller
in .h file
NSString *videourl;
@property(nonatomic,retain) NSString *videourl;
in .m file
@synthesize videourl;
-(void)viewDidLoad
{
[self loadWebview];
}
-(void)loadWebview
{
NSString *urlAddress = videourl;
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[_youtube_web(your webview object) loadRequest:requestObj];
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow