2013-06-26 53 views
0

我正在通過viewDidLoad在UIWebView上加載URL。無法通過代碼將UIWebView重新加載到新的URL

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL  
    URLWithString:@"http://abc.com/Test.html"]]]; 
} 

然後在NSTimer上運行以下命令來執行javascript。對JavaScript的調用效果很好。

-(void)WebViewLoad:(NSTimer *)theTimer 
{ 

    NSString *abcFiles = [webView stringByEvaluatingJavaScriptFromString:@"abc.length"]; 
    NSLog(@"The TotalNumberOfFiles is %i",abcFiles); //This works 
//-------------------------------------------------------- 
    NSString *currentURL = webView.request.URL.absoluteString; 
    NSLog(@"Current url 1 is %@",currentURL); 

    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://abc.com/newpage.html"]]]; 
    [self.view addSubview:webView]; 


    NSString *currentURL2 = webView.request.URL.absoluteString; 
    NSLog(@"Current url 2 is %@",currentURL2); 
} 

註釋行上方的所有內容均適用。 但是添加新URL的部分,我仍然得到初始URL。 我試着添加重新加載。它不起作用。 嘗試創建一個新的UIWebView對象也無法工作。

結果是

Current url 1 is http: //abc.com/Test.html 
Current url 2 is http: //abc.com/Test.html 

我想

Current url 1 is http: //abc.com/Test.html 
Current url 2 is http: //abc.com/newpage.html 

另一個問題是,「我們可以加載從代碼的新網址。它不是通過按鈕或任何行動來了。它來自何處一個循環計時器,這是一個問題嗎?「

回答

0

的原因,你沒有看到你所期望的要求是,UIWebViewrequest財產不受loadRequest:改變,直到請求之後已經滿載,包括所有的重定向和資產。

+0

你說得對。我意識到,如果我嘗試一個接一個地加載頁面,他們不會被加載。所以我改變了它繼續輪詢,直到第一頁完成加載,然後再次撥打電話。非常感謝 – rayfish

相關問題