0
問題是以下幾點: 我試圖從html中使用「stringByEvaluatingJavaScriptFromString」來獲取表。表本身被拉到NSLog中,但她不想出現在UIWebView中。這裏是我的代碼:從index.html提取表objective-c
- (void)viewDidLoad
{
[super viewDidLoad];
paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
filePath = [NSString stringWithFormat:@"%@/%@", [paths objectAtIndex:0],@"index.html"];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:filePath]]];
}
- (void)webViewDidFinishLoad:(UIWebView*)webView1
{
NSLog(@"webViewDidFinishLoad");
html = [webView stringByEvaluatingJavaScriptFromString: @"document.body.getElementsByClassName('bottomwideborder')[1].innerHTML;"];
html1 = [NSString stringWithFormat:@"<html><body>%@</body></html>", html];
[webView loadHTMLString:html1 baseURL:[NSURL URLWithString:filePath]]; //Here page does not refresh
NSLog(@"%@", html1); //It's all displayed
[webView stopLoading];
}
我覺得這個頁面應該以某種方式更新,但我不知道如何((
請幫助
然後,我得到一個錯誤 - 本地聲明的「web視圖」隱藏實例變量 – IlyaKharlamov
因此,我只顯示index.html,但它沒有更新。在NSLog輸出是我需要的! – IlyaKharlamov
哦,我明白你想要做什麼(和UGH)。不要做這種雙Web查看加載。嘗試一種不同的方法:加載一個「'NSString'」對象(通過類似['[NSString initWithContentsOfURL:encoding:error:]'](http:// developer .apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html#// apple_ref/occ/instm/NSString/initWithContentsOfURL:encoding:error :)然後解析你的「table 「出來,並加載解析表HTML到您的網頁視圖。 –