2014-07-10 22 views
0

我需要加載doc和ppt文件在UIWebView。 我在一個控制器中有兩個不同的UIWebViewUIWebview加載ppt和文檔崩潰應用

[self.webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[[NSBundle mainBundle] pathForResource:@"doc" ofType:@"doc"]]]]; 
[self.webview1 loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[[NSBundle mainBundle] pathForResource:@"ppt" ofType:@"ppt"]]]]; 

這個崩潰的應用程序:

OfficeImport`WrdEshBackground::takeClientData(WrdEshClientData*): 
0x34c4fe3c: str.w r1, [r0, #224] //on this line 

但如果我加載文件具有相同的格式:

[self.webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[[NSBundle mainBundle] pathForResource:@"ppt" ofType:@"ppt"]]]]; 
[self.webview1 loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[[NSBundle mainBundle] pathForResource:@"ppt" ofType:@"ppt"]]]]; 

它工作得很好。

如果我等待UIWebView完成加載第一個請求,然後從第二個啓動它運行良好。 但我需要在tableView中加載很多文件。 UITableViewCel將包含加載這個文件的UIWebView

回答

-1

我建議,我曾用來顯示使用NSData對象MIME類型數據到web視圖的方式,我有我的文件轉換爲NSData對象,並顯示像

if ([docType isEqualToString:@"pdf"]) { 
    [webView loadData:documentDataObject MIMEType:@"application/pdf" textEncodingName:@"utf-8" baseURL:nil]; 
} else if ([docType isEqualToString:@"doc"]) { 
    [webView loadData:documentDataObject MIMEType:@"application/msword" textEncodingName:@"utf-8" baseURL:nil]; 
} else if ([docType isEqualToString:@"docx"]) { 
    [webView loadData:documentDataObject MIMEType:@"application/vnd.openxmlformats-officedocument.wordprocessingml.document" textEncodingName:@"utf-8" baseURL:nil]; 
} else if ([docType isEqualToString:@"jpg"]) { 
    [webView loadData:documentDataObject MIMEType:@"image/jpeg" textEncodingName:@"utf-8" baseURL:nil]; 
} else if ([docType isEqualToString:@"png"]) { 
    [webView loadData:documentDataObject MIMEType:@"image/png" textEncodingName:@"utf-8" baseURL:nil]; 
} 
+0

我試試你的代碼,但它不」幫助。 'NSString * pdfPath = [[NSBundle mainBundle] pathForResource:@「doc」ofType:@「doc」]; NSData * myData = [NSData dataWithContentsOfFile:pdfPath]; [self.webview loadData:myData MIMEType:@「application/msword」textEncodingName:@「utf-8」baseURL:nil]; [self.webview1 loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[[NSBundle mainBundle] pathForResource:@「ppt」ofType:@「ppt」]]]];'此錯誤 OfficeImport'WrdEshReader :: readClientAnchor(EshContentBase&, EshHeader const&):0x34bc79b8:str.w r4,[r0,#348] – user2545330

+0

我想你的doc文件有問題,請嘗試另一個文件 – Retro

+0

doc文件中沒有問題,如果我嘗試加載它這兩個'webview'它工作得很好,但如果不同類型的文件在不同的webview中的一個線程崩潰的應用程序 – user2545330