2012-08-22 135 views
0

我試圖在webview中顯示pdf,但webview始終爲白色/空白。 如果我登錄從本地文件的路徑,就可以登錄,所以該文件是有..iOS:在WebView中顯示PDF

這裏是我的代碼:

NSString *path = [[NSBundle mainBundle] pathForResource:@"fileName" ofType:@"pdf"]; 
NSURL *targetURL = [NSURL fileURLWithPath:path]; 
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL]; 
[webView loadRequest:request]; 

(Webview是一個IBOutlet)

MAIK

+1

你確定你已經連接了IB上的所有東西嗎?你的代碼看起來不錯...你確定你看到的白色/空白視圖是webview嗎? –

+0

是的,我不能滾動它,縮放等...... – Maik639

+0

只是因爲你可以滾動和縮放並不意味着它的「連接」...在調試器中,是webView ==零? – CSmith

回答

0

請確保啓用了用戶交互功能&多點觸控已啓用。 check for the following properties

0

您的targetURL可能爲零,請調試此操作。

如果targetUrl爲零,這可能是'路徑'有空間。

所以,你應該編碼路徑:

//Encode Url 
+(NSString *) urlEncodeString:(NSString *) str 
{ 
    return [str stringByReplacingOccurrencesOfString:@" " withString:@"%20"]; 
} 
0

控制整個字符,而不是不只是空間更appropriate.Try這一個編碼文件的路徑。

-(NSString *)urlenc:(NSString *)val{ 
    CFStringRef safeString = 
    CFURLCreateStringByAddingPercentEscapes(NULL, 
              (CFStringRef)val, 
              NULL, 
              CFSTR("/%&=?$#[email protected]<>|*,.()[]{}^!şığüöçĞÜŞİÖÇ"), 
              kCFStringEncodingUTF8); 
    return [NSString stringWithFormat:@"%@", safeString]; 
}