2013-02-05 45 views
-2

我使用下面的代碼解僱模式視圖控制器:dismissModalViewControllerAnimated在IOS崩潰6.0的iPad模擬器

- (IBAction)done { 
#ifdef __IPHONE_5_0 
    if ([self respondsToSelector:@selector(presentingViewController)]) 
     [self.presentingViewController dismissModalViewControllerAnimated:YES]; 
    else 
#endif 
     [self.parentViewController dismissModalViewControllerAnimated:YES]; 
} 

如果我欠幅脈衝模擬器,他使用的iOS 4.3的iPad,它採用self.parentViewController和工作正常。但是,當我使用iOS 6.0 iPad模擬器時,模擬器在使用self.presentingViewController解除視圖後立即崩潰。

我沒有真正的iPad來測試......任何想法?

編輯:

下面是創建模態視圖控制器的代碼。

NSArray* errors = [[NSArray alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Errors" ofType:@"plist"]]; 

UIViewController* vc; 
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { 
    DocumentsViewController_iPad* docsVC = [[DocumentsViewController_iPad alloc] initWithNibName:@"DocumentsViewController-iPad" bundle:nil]; 
    docsVC.documents = errors; 
    docsVC.errors = YES; 
    docsVC.navTitle = @"Troubleshooting"; 
    vc = docsVC; 
} else { 
    DocumentsViewController* docsVC = [[DocumentsViewController alloc] initWithNibName:nil bundle:nil]; 
    docsVC.documents = errors; 
    docsVC.errors = YES; 
    docsVC.navTitle = @"Troubleshooting"; 
    vc = docsVC; 
} 

vc.modalTransitionStyle = UIModalTransitionStyleCoverVertical; 
[self presentModalViewController:vc animated:YES]; 
[vc release]; 
+0

爲什麼會反對票? – Mausimo

回答

3

有幾件事情:

  • 是的,你應該使用dismissViewControllerAnimated:completion:作爲@rdelmar說
  • 你應該調用它presentingViewController,沒有父母
  • 可以跳到要去呈現控制器和解僱self ,如果需要,它會將這個消息轉發給呈現控制器。
1

dismissModalViewControllerAnimated:折舊,使用dismissViewControllerAnimated:完成:代替。

+0

已棄用,但尚未銷售。使用它不應該導致崩潰,但。 –

+0

感謝您的回覆。我只是改變爲dismissViewControllerAnimated:完成:它仍然崩潰。 – Mausimo

+0

@Mausimo,你是否添加了一個異常斷點來查看它是否能夠找出錯誤發生的位置?我懷疑你的錯誤是在別的地方。 – rdelmar

相關問題