2015-07-20 54 views
1

我想使用AFNetworking將網頁加載到我的UIWebView。我已經將AFNetworking庫導入到我的項目中並用於加載圖像。 我想要一個代碼來加載網頁。您的幫助。謝謝!如何使用AFNetworking在ios中加載網頁到UIWebView

這是我如何加載images.it工作正常。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    HomeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"homereuseIdentifier"]; 
    Home *mogoHome = [homepost objectAtIndex:indexPath.row]; 

    NSString *homeimageurlname = [NSString stringWithFormat:@"%@", mogoHome.homeImage]; 
    NSURL *homeimageurl = [NSURL URLWithString:homeimageurlname]; 

    cell.hometitleLabel.text = mogoHome.homeTitle; 
    [cell.homeimageView setImageWithURL:homeimageurl placeholderImage:nil]; 
    cell.timeLabel.text = [[mogoHome.modifiedTime componentsSeparatedByString:@" "] objectAtIndex:1]; 
    return cell; 
} 

但我用正常的方式來至於我能理解你不能加載網頁

NSString *finalString = [NSString stringWithFormat:@"%@", self.home.homewebUrl]; 
    NSURL *finalurl = [NSURL URLWithString:finalString]; 
    NSURLRequest *finalReques = [NSURLRequest requestWithURL:finalurl]; 
    [self.finalwebView loadRequest:finalReques]; 
+0

@ anuk--如果你顯示你的代碼很容易就可以解決問題 –

+0

你的意思是你想讓AF下載html並在UIWebView中顯示而不是在UIWebView中加載html? –

+0

是@Toni李我想加載使用AF –

回答

0

! 如果您想在UIWebView中顯示任何內容(HTML或任何基於Web的內容),那麼您必須僅通過NSURL來完成。使用AFNetworking,你可以下載HTML文件(如果它是一個文件),但是UIWebview中的加載過程必須由蘋果提供給我們的那些實現,是的,它需要一些時間,但是如果你想要優化,那麼不要使用UIWebview

+0

而不是那個我應該使用@Saheb Roy –

+0

如果你想避免滯後,我認爲最好的事情是下載整個內容並將其顯示在自定義的ViewController中,但只有在您已經知道內容如何的情況下才會起作用。但這將是很多工作..並且慢得多,或者您可以在單擊單元格後在Safari中打開頁面,這樣用戶無法做任何事情。 或者你堅持使用webview –

+0

好的,我會盡力而爲。 thanx爲您的建議。 @薩希布羅伊 –

相關問題