【问题标题】:Undefined self.view for presentOpenInMenuFromRectpresentOpenInMenuFromRect 的未定义 self.view
【发布时间】:2012-08-31 21:56:15
【问题描述】:

我正在尝试将“presentOpenInMenuFromRect”功能添加到 Rhomobile。但是,我无法引用当前视图。

Rhomobile 函数(### 标记我的补充):

- (void)openDocInteractCommand:(NSString*)url {
if (NSClassFromString(@"UIDocumentInteractionController")) {
    NSURL *fileURL = [NSURL fileURLWithPath:url];

    UIDocumentInteractionController* docController = [UIDocumentInteractionController interactionControllerWithURL:fileURL];

    docController.delegate = self;//[AppManager instance];

    BOOL result = [docController presentPreviewAnimated:YES];

    if (!result) {
      ###
        BOOL isValid = [docController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES];
      ###
    }    
}
}

基本上,如果预览失败,我想打开“打开方式”菜单,因为我正在尝试打开一个 .KMZ(Google 地球 KML 文件)并且它不能预览。

完整源代码:https://github.com/rhomobile/rhodes/blob/master/platform/iphone/Classes/AppManager/AppManager.m

谢谢,

尼克,

【问题讨论】:

    标签: ios rhomobile


    【解决方案1】:

    这是解决我问题的代码:

      - (void)openDocInteractCommand:(NSString*)url { // inView:(UIView*)view
    if (NSClassFromString(@"UIDocumentInteractionController")) {
        NSURL *fileURL = [NSURL fileURLWithPath:url];
    
        UIDocumentInteractionController* docController = [UIDocumentInteractionController interactionControllerWithURL:fileURL];
    
        docController.delegate = self;//[AppManager instance];
    
        BOOL result = [docController presentPreviewAnimated:YES];
    
        if (!result) {
            [docController retain];
            CGPoint centerPoint = [Rhodes sharedInstance].window.center;
            CGRect centerRec = CGRectMake(centerPoint.x, centerPoint.y, 0, 0);
            BOOL isValid = [docController presentOpenInMenuFromRect:centerRec inView:[Rhodes sharedInstance].window animated:YES];
        }
    }
    }
    
    - (void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController *)docController
    {
    [docController autorelease];
    }
    

    【讨论】:

      【解决方案2】:

      AppManager 类继承自 NSObject 而不是 UIViewController - 为什么它会有一个名为 view 的属性?您必须找到另一种方式来呈现您的视图或视图控制器(可能使用应用程序的主窗口)。

      【讨论】:

      • 好吧,我是新手。你能从源头上告诉你如何进入主窗口吗?我试过这个: BOOL isValid = [docController presentOpenInMenuFromRect:CGRectMake(300, 300, 100, 100) inView:[Rhodes sharedInstance].window animated:YES];但它给出了这个错误:***由于未捕获的异常“NSGenericException”而终止应用程序,原因:“-[UIPopoverController dealloc] 在弹出窗口仍然可见时达到。” --- 我从未见过“打开方式...”菜单。
      • @user506706 你可以使用[[UIApplication sharedApplication] keyWindow],但我认为这在这里不太相关...... :(
      • 使用此解决方案解决了它:stackoverflow.com/questions/12222940/…
      猜你喜欢
      • 2011-10-14
      • 1970-01-01
      • 2010-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-03
      相关资源
      最近更新 更多