2013-04-08 14 views
12

我有兩個UIViewController類,其中在FirstClass我有一個用於UIButton登錄,當用戶輕敲按鈕,我將顯示SecondClass ...對於我已經做了,嘗試從視圖控制器以關閉而呈現或駁回正在進行

SecondClass *index = [[SecondClass alloc] init]; 
[self presentModalViewController:index animated:YES]; 

在二等,我有一個註銷按鈕,它會重定向到的Firstclass,爲我所做的一切,

[self dismissModalViewControllerAnimated:YES]; 

,當我在二等按下退出按鈕,我得到的警告味精

**Attempt to dismiss from view controller <FirstClass: 0e39w88e160> while a presentation or dismiss is in progress!** 

有什麼問題在這裏..

回答

2

呼叫,您註銷&這些行,然後檢查:

if (![[self modalViewController] isBeingDismissed]) 
{ 
    [self dismissModalViewControllerAnimated:YES]; 
} 
1

有很多事情可能會導致這種情況,這裏有一些選擇:

  1. 您忘記調用ViewController方法之一,例如viewWillAppear,viewWillAppear等。請參閱UIViewController文檔以查看何時必須調用super。
  2. dismissModalViewControllerAnimated:方法被多次調用,如果您多次將目標添加到UIButton,就會發生這種情況。

爲了更好地理解問題,請粘貼兩個視圖控制器的代碼的完整代碼。

27

新增不論是iOS 6和預iOS 6的答案:

的iOS 5.0及更高版本

當你註銷,解散前增加這個檢查:

if (![self.presentedViewController isBeingDismissed]) 
{ 
    [self dismissModalViewControllerAnimated:YES completion:nil]; 
} 

的iOS 4。 X以下

解僱之前添加此檢查:

if (![[self modalViewController] isBeingDismissed]) 
{ 
    [self dismissModalViewControllerAnimated:YES]; 
} 
+0

presentedViewController和dismissViewControllerAnimated:完成:可從的iOS 5.0 – 2013-09-04 12:19:17

+1

感謝@PavelAlexeev,我的文檔驗證和更新我的答案。 – 2013-09-04 14:59:12

相關問題