2011-12-09 40 views
0

我有用於彈出設置屏幕的導航界面,每次使用按設置按鈕。ios:使用modalTransitionsytle屬性導航到另一個屏幕,崩潰應用程序

@interface Navigation : UINavigationController 
{ 
} 
-(void)popToMainMenuAnimated:(BOOL)animated; 

//.m file 
-(void)popToMainMenuAnimated:(BOOL)animated 
{ 
    UIViewController *element; 
    for(element in self.viewControllers) 
    { 
     if([element isKindOfClass:[MainSettingClass class]]){ 
      self.modalTransitionStyle = UIModalTransitionStylePartialCurl; 
      [self presentModalViewController:element animated:YES] 
     } 
    } 
} 

應用程序崩潰與下面的異常。

*因未捕獲異常'NSInvalidArgumentException'而終止應用程序,原因:'應用程序試圖以模態方式呈現活動控制器。' *第一次撥打電話堆棧:

注意:這不是根屏幕,而是我的應用程序的第3個屏幕。在調試

回答

1

數據庫日誌,你給我一個理由通過搜索:
MainSettingClass例如,你推前既不能再次repushed到navigationController的陣列,也可以模態呈現。您應該創建一個新的MainSettingClass實例並呈現它,就像第二個代碼片段一樣。

HERE是一個涉及到的問題,提到Application tried to present modally an active controller。 :)

但是,爲什麼不loadMain Menu,而不是pop

-(void)loadMainMenuAnimated:(BOOL)animated 
{ 
    MainSettingClass * mainMenuViewController = [[[MainSettingClass alloc] init] autoreleased]; 
    [mainMenuViewController.view setFrame:CGRectMake(0.0f, 0.0f, 320.0f, 480.0f)]; 
    // ... 
    self.modalTransitionStyle = UIModalTransitionStylePartialCurl; 
    [self presentModalViewController:mainMenuViewController animated:YES]; 
} 

而且告訴你代碼中有一些錯誤:

self.modalTransitionStyle= UIModalTransitionStylePartialCurl; 
[self popToViewController:element animated:YES]; 

self.modalTransitionStyle= UIModalTransitionStylePartialCurl;如果你設置這一項,你需要使用

[self presentModalViewController:yourViewController animated:YES]; 

[self popToViewController:element animated:YES]; 
+0

我按照建議做了更改,但這導致我的應用程序崩潰。以前只有轉換屬性不服從,不管我選擇哪種風格,總是以默認方式轉換。 –

+0

Transition正在與 正確地發生[self popToViewController:element animated:YES]; 但我想過渡不是默認的,而是UIModalTransitionStylePartialCurl。 當我嘗試您的更改: [self.modalTransitionStyle = UIModalTransitionStylePartialCurl; [self presentModalViewController:element animated:YES]; 應用程序崩潰。 –

+0

@RakeshSingh我很抱歉我的錯誤。現在怎麼樣? – Kjuly

1

看來您正在挑選並嘗試呈現(模態)的'MainSettingsClass'UIViewController已處於活動狀態。如果你把代碼放在視圖控制器可能以前被推送/呈現(理想地被彈出/解除)的位置,這將會有所幫助。

這裏有一個couplerelated的問題,可能會幫助你。

相關問題