2012-08-31 27 views
1

我想添加「presentOpenInMenuFromRect」功能給Rhomobile。但是,我無法引用當前視圖。未定義的self.view爲presentOpenInMenuFromRect

的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]; 
     ### 
    }  
} 
} 

從本質上講,如果預覽失敗,我想打開「打開方式」菜單,因爲我; mtrying開.KMZ (Google地球KML文件),並且無法預覽。

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

感謝,

尼克,

回答

1

的AppManager的類從NSObject的,而不是從UIViewController的繼承 - 怎麼就那麼它將有一個屬性命名view?你必須找到另一種方式來呈現你的視圖或視圖控制器(也許使用應用程序的主窗口)。

+0

好吧,我是個新手。你能否告訴我們如何到達主窗口?我試過這個:BOOL isValid = [docController presentOpenInMenuFromRect:CGRectMake(300,300,100,100)inView:[Rhodes sharedInstance] .window animated:YES];但它給出了這個錯誤:***終止應用程序由於未捕獲的異常'NSGenericException',原因:' - [UIPopoverController dealloc]達到彈出仍然可見。' ---我從未見過「Open In ...」菜單。 – user2666194

+0

@ user506706你可以使用[[UIApplication sharedApplication] keyWindow],但我認爲這不是很相關... :( – 2012-09-01 11:48:27

+0

解決它使用此解決方案:http://stackoverflow.com/questions/12222940/undefined-self-查看目前打開的菜單很不錯 – user2666194

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