为什么UIDocumentinteractioncontroller没有显示菜单?

时间:2011-06-29 12:10:06

标签: objective-c uidocumentinteraction titanium-modules

有一段时间我正在创造一个定制的钛模块。我正试图在otrher应用程序中打开pdf。 一切似乎都是正确的(没有警告等) 但是在de navBar中按下按钮时没有显示菜单。

以下是显示菜单的方法代码:

ENSURE_SINGLE_ARG_OR_NIL(args,NSDictionary);

TiViewProxy* viewAnchor = [args objectForKey:@"view"];
NSString* fileToOpen = [args objectForKey:@"url"];



NSLog(@"%@",fileToOpen);

if(viewAnchor != nil){
    NSLog(@"viewAnchor is not nil accessing controller");
    NSLog(@"%@",[TiUtils toURL:fileToOpen proxy:self]);

    CGRect rect = [TiUtils rectValue:args];
    self.controller = [[UIDocumentInteractionController interactionControllerWithURL:[TiUtils toURL:fileToOpen proxy:self]] retain];
    self.controller.delegate = self;

    BOOL menuDisplayed = [self.controller presentOpenInMenuFromBarButtonItem:[viewAnchor barButtonItem] animated:YES];

    //menuDisplayed = YES
    if(menuDisplayed)
    {
        NSLog(@"Menu is displayed");
        //This display's com.adobe.pdf
        NSLog(@"%@",self.controller.UTI);
    }
    else
    {
        NSLog(@"Menu failed to display");
    }
}

1 个答案:

答案 0 :(得分:0)

模块方法在非UI线程上运行,但是,必须在主UI线程上执行所有UIKit方法。您需要确保您的方法在具有宏的UI线程上运行:

ENSURE_UI_THREAD_1_ARG(args);

更多详情:

https://wiki.appcelerator.org/display/guides/iOS+Module+Development+Guide#iOSModuleDevelopmentGuide-AddingSpecialCompilerDirectives