2013-06-12 53 views
0

我只是爲iOS創建一個文件瀏覽器,我只需要知道如何在UIWebview中打開任何類型的文件。我認爲webview可以打開任何類型的文件,這是因爲我選擇使用UIWebView直接在應用程序中查看文件。現在我的問題。如何在UIWebView中打開文件?

如何以編程方式切換到UIVtoryBoard中的UIViewController並顯示該文件?文件URL存儲在名爲path的字符串中。

這是我的收費,我只需要添加文件查看器。 enter image description here

有人可以幫我嗎?

+0

爲什麼不使用文件管理器?而不是UIWebView .. – lakesh

+0

我不知道這個 –

+0

閱讀關於NSFileManager ... – lakesh

回答

0
-(void) displayFile:(NSString*)fileName 
{ 
    NSError *error = nil; 
    NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; 
    TO get the filename 
    NSString *folderPath = [documentsDirectory stringByAppendingPathComponent:fileName]; 

    if (![[NSFileManager defaultManager] fileExistsAtPath:folderPath]) //Optionally check if folder already hasn't existed. 
    { 
    // do something 
    } 
} 

希望這有助於你...

+0

類型,我需要知道如何從我在上面的帖子中向您展示的表格視圖切換到位於UIViewController中的UIWebView。我喜歡製作一個pushViewController動畫。 –

+0

使用didSelectRowAtIndexPath方法... - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath :(NSIndexPath *)indexPath – lakesh

+0

我已經有了這個,我只需要知道命令切換到其他UIViewController –