2011-10-01 85 views
0

當我的iOS應用程序被激活時,點擊應用程序支持的文件(FTA)時,我想在applicationDidBecomeActive中顯示一個模態視圖。由於我想控制回來,當模態視圖被解散時,我使用NSRunLoop和一個標誌來檢測視圖被解散。請參閱附件中的代碼。當調用[NSRunloop runUntilDate]時,我的視圖顯示在當前視圖的後面,並且不響應鍵盤/鼠標操作。任何想法正在發生。在applicationDidBecomeActive中調用NSRunLoop方法會導致系統不響應

[CODE]

- (void) applicationDidBecomeActive:(UIApplication *)application { 


//App activated due to file selection in an email attachment, display modal dialog 
if (fileSelected) 
{ 
    RSAImportViewController *s = [[RSAImportViewController alloc] initWithNibName:@"RSAImportViewController_iPad" bundle:nil]; 

    UINavigationController* rNC = [[UINavigationController alloc] initWithRootViewController:s]; 

    [rNC setModalPresentationStyle:UIModalPresentationFormSheet]; 
    [rNC setModalTransitionStyle:UIModalTransitionStyleCoverVertical]; 

    [nav presentModalViewController:rNC animated:YES]; 

// wait for modal view to be dismissed, the modal view is dismissed when ok/cancel 
// buttons are clicked. 

    while (s.completion == requestRunning) { 
    [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0]]; 
} 

[s dismissKeyboard]; 

// Do further processing 

return; 
} 

回答

1

那不是NSRunLoop方法對。

您應該將自己設置爲模態視圖的代表,並讓模態視圖在其被解散時通知它的代表 - 並根據需要調用任何其他方法來執行任何您想要執行的操作。

在RSAImportViewController.h:

@class RSAImportViewController 
@protocol RSAImportViewControllerDelegate 
-(void)rsaImportViewControllerDone:(RSAImportViewController*)vc; 
@end 

@interface RSAImportViewController 
... 
@property(assign) id<RSAImportViewControllerDelegate> delegate; 
@end 

在RSAImportViewController.m,等。無論您撥打dismissModalViewControllerAnimated:方法:

@implementation RSAImportViewController 
@synthesize delegate; 
... 
-(void)someMethodInYourCode { 
    ... 
    [self dismissModalViewControllerAnimated:YES]; 
    // call the delegate method to inform we are done (adapt to your needs) 
    [self.delegate rsaImportViewControllerDone:self]; 
} 
... 
@end 

而在AppDelegate中:

- (void) applicationDidBecomeActive:(UIApplication *)application { 
{ 
    if (fileSelected) { 
     ... 
     rNC.delegate = self; // set 'self' to be informed when the rNC is dismissed 
     [nav presentModalViewController:rNC animated:YES]; 
    } else { 
     [self doFurtherProcessing]; 
    } 
} 
-(void)rsaImportViewControllerDone:(RSAImportViewController*)vc { 
    [self doFurtherProcessing]; 
} 
-(void)doFurtherProcessing { 
    [s dismissKeyboard]; 
    // and all your other stuff 
} 
+0

謝謝!這有助於幫助 –

+1

酷:)因爲我看到你是新手,所以如果它解決了你的問題,不要忘了點擊答案旁邊的複選標記,將你的問題標記爲已解決,讓其他人知道。 – AliSoftware

相關問題