我正在尝试将“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(谷歌地球KML文件),它不能是预览。
完整源代码:https://github.com/rhomobile/rhodes/blob/master/platform/iphone/Classes/AppManager/AppManager.m
谢谢,
尼克,
答案 0 :(得分:1)
AppManager类继承自NSObject而不是UIViewController - 它怎么会有一个名为view
的属性?您必须找到另一种方式来呈现您的视图或视图控制器(可能使用应用程序的主窗口)。
答案 1 :(得分: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];
}