2013-07-30 56 views
1

到目前爲止,我已經完成並實施了http://mobiforge.com/developing/story/importing-exporting-documents-ios到我的項目中。然而這沒有任何作用。我試圖讓它在受支持的應用程序中打開任何文件。在表格視圖中打開文件到其他應用程序

我已經在我的.h和.m中聲明。

.h 
UIDocumentInteractionController *documentController; 
@property (retain) UIDocumentInteractionController *documentController; 

.m 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    [cellTapSound play]; 
    [self.tableView deselectRowAtIndexPath:indexPath animated:NO]; 

    [self openDocumentIn]; 

} 

-(void)openDocumentIn { 
    NSString * filePath = self.directoryPath = @"/var/mobile/Documents/downloads"; 
    documentController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]]; 
    documentController.delegate = self; 
    [documentController retain]; 
    documentController.UTI = @"public.deb" @"public.zip" @"public.text" @"com.apple.quicktime-movie" @"com.adobe.pdf"; 
    [documentController presentOpenInMenuFromRect:CGRectZero 
              inView:self.view 
             animated:YES]; 
} 

-(void)documentInteractionController:(UIDocumentInteractionController *)controller 
     willBeginSendingToApplication:(NSString *)application { 

} 

-(void)documentInteractionController:(UIDocumentInteractionController *)controller 
      didEndSendingToApplication:(NSString *)application { 

} 

-(void)documentInteractionControllerDidDismissOpenInMenu: 
(UIDocumentInteractionController *)controller { 

} 

任何幫助或指導,將不勝感激。

UPDATE 8/1

所以我設法得到它的工作,當然,這是不會發生的唯一的事情,無論是應用程序我選擇打開,它不顯示文件。例如Dropbox。以下是我更新的半工作代碼。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    [cellTapSound play]; 
    [self.tableView deselectRowAtIndexPath:indexPath animated:NO]; 


    NSString *filePath = [directoryContents objectAtIndex:indexPath.row]; 

    UIDocumentInteractionController *interactionController = [[UIDocumentInteractionController alloc] init]; 
    [interactionController setURL:[NSURL fileURLWithPath:filePath]]; 
    [interactionController setUTI:@"public.filename-extension"]; 

    [interactionController setDelegate:self]; 
    [interactionController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES]; 


} 

我想我需要在這裏聲明某處,只是不知道是什麼。

-(void)documentInteractionController:(UIDocumentInteractionController *)controller 
     willBeginSendingToApplication:(NSString *)application { 

} 


-(void)documentInteractionController:(UIDocumentInteractionController *)controller 
      didEndSendingToApplication:(NSString *)application { 

} 

卡住了,有什麼想法嗎?

UPDATE 8/6

出noobish好運氣的我得到它的工作:)下面貼的答案。

雖然沒有人在這裏回答,但我希望這可以幫助別人。

+0

發佈使用新代碼更新。 – ChrisOSX

+0

可否請您發佈.h和.m文件..我正在嘗試相同和文件wouldnt打開並沒有看到任何錯誤.. –

+0

.h和.m的什麼?我的文檔視圖控制器? – ChrisOSX

回答

0

繼承人是什麼讓它爲我工作。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    [cellTapSound play]; 
    [self.tableView deselectRowAtIndexPath:indexPath animated:NO]; 


    NSString *fileName = [directoryContents objectAtIndex:indexPath.row]; 

    NSString *path; 
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    path = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"my downloads"]; 
    path = [path stringByAppendingPathComponent:fileName]; 

    documentController = [[UIDocumentInteractionController alloc] init]; 
    documentController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:path]]; 

    [documentController setDelegate:self]; 
    [documentController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES]; 
    [documentController retain]; 
} 
相關問題