1

我在第一個viewcontroller中有一個uiwebview,並且在第二個控制器上有一個uibutton,當我點擊uibutton時,我正在改變加載請求。事情是,網址改變了,但webview沒有重新加載。如何從另一個視圖控制器加載uiwebview

FirstViewController

-(void)viewDidLoad 
{ 
    [email protected]"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* [email protected]"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 

但是WebView中沒有加載,我想加載www.apple.com.Thanks提前

回答

0

你彈出關於第一個視圖控制器按鈕click.write.So的觀點寫爲什麼你分配一個新的控制器對象的loadWebView在viewWillAppear中,而不是在viewWillLoad.And的secondController方法並彈出一個視圖控制器無需分配和加載。只需彈出視圖即可。

0

你是在第二個視圖控制器中調用加載第一個視圖控制器的方法nd WebView作爲第一個視圖控制器的子視圖。因此,您需要推動您的第一個視圖控制器來查看效果。在第二個視圖控制器中,您無法看到第一個視圖控制器上發生了什麼。

+0

看到我的代碼,我不想看到第二個視圖controller.when我點擊第二個viewcontroller的uibutton它去第一個視圖,我想看看 - – IosAdvocate

+0

簡要解釋 – Sierra

0
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]; 
    [email protected]"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]; 

} 
+0

看到我的代碼,我不想看到第二個視圖當我點擊第二個viewcontroller的uibutton時,它會轉到第一個視圖,我想看到它 – IosAdvocate

相關問題