UIDocumentInteractionController presentPreviewAnimated:返回NO并且不显示预览

时间:2011-09-09 19:50:56

标签: iphone ios

我已经尝试了所有我能想到的东西,它仍然没有回应,而且Apple没有任何提示。

- (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;
}

2 个答案:

答案 0 :(得分:6)

1)你有信心你打开的文件是犹太教的吗?如果没有,那么返回NO将是期待的事情

2)我对你的委托方法感到困惑。本方法很乐意自己完成对导航控制器的推送。如果你使用这个代码,你会更好吗? (有关基本原理,请参阅docs。)

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

答案 1 :(得分:0)

我遇到了与presentPreviewAnimated类似的问题,返回NO。在我的情况下,我错过了文件的扩展名。当我将文件从document重命名为document.xlsx时,它已成功打开。