2011-09-09 46 views
3

我試過了所有我能想到的東西,它仍然響應NO,而Apple沒有任何提示。UIDocumentInteractionController presentPreviewAnimated:返回NO並且不顯示預覽

- (void)connectionDidFinishLoading:(NSURLConnection *)connection 
{ 
    NSLog(@"finished!"); 

    NSString *tempString = [NSString stringWithFormat:@"file://%@%@", NSTemporaryDirectory(), [[NSProcessInfo processInfo] globallyUniqueString]]; 
    NSURL *tempURL = [NSURL URLWithString:tempString]; 
    [receivedData writeToURL:tempURL atomically:YES]; 

    NSLog(@"tempURL is written!"); 

    UIDocumentInteractionController *interactionController = [UIDocumentInteractionController interactionControllerWithURL:tempURL]; 
    interactionController.delegate = self; 
    [interactionController retain]; 
    NSLog(@"--- %i", [interactionController presentPreviewAnimated:YES]); 
    NSLog(@"presented preview"); 

    [connection release]; 
    [receivedData release]; 
} 

- (UIViewController*)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller 
{ 
    NSLog(@"asdf"); 
    UIViewController *viewController = [[[UIViewController alloc] init] autorelease]; 
    [self.navigationController pushViewController:viewController animated:YES]; 
    return viewController; 
} 
+0

您是否檢查tempUrl是否不爲空? – Adriana

回答

6

1)您是否確信您打開的文件是猶太潔食?如果不是,那麼返回NO將是預期的事情

2)我很迷惑你的委託方法。目前的方法很樂意將自己推到導航控制器上。如果你使用這個代碼,你會更好嗎? (見docs的理由。)

- (UIViewController *) documentInteractionControllerViewControllerForPreview: (UIDocumentInteractionController *) controller 
{ 
    return [self navigationController]; 
} 
+0

1)我正在使用PDF和HTMl文件。 2)我之前嘗試過,並沒有得到更好的結果。我改回它,仍然得到0。 –

0

我有presentPreviewAnimated類似的問題,它沒有返回。在我的情況下,我錯過了文件的擴展名。當我將文件從文檔重命名爲document.xlsx時,它已成功打開。

相關問題