2014-04-01 198 views
0

我是IOS編程新手。我想問一下如何在呈現的視圖中實例化導航控制器。這是我從前面的視圖實例化我的導航欄的方式。導航控制器呈現視圖

SWRevealViewController *revealController = self.revealViewController; 

    UINavigationController *frontNavigationController = (id) revealController.frontViewController; 

    if (! [frontNavigationController.topViewController isKindOfClass:[CalibrateViewController class]]) { 
     CalibrateViewController *promotionViewController = [[CalibrateViewController alloc] init]; 
     UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:promotionViewController]; 
     [revealController setFrontViewController:navigationController animated:YES]; 
    } 
    else { 
     [revealController revealToggle:self]; 
    } 

但是,當我想以現在的看法做到這一點,

LoginViewController *promotionViewController = [[LoginViewController alloc] init]; 
[self presentViewController:promotionViewController animated:YES completion:nil]; 

我不知道要放什麼時候想用presentView實例。

任何幫助將不勝感激。提前致謝。

對不起,我感到困惑。基本上我想做這樣的事情:

  1. 我有一個主視圖,我們將其命名爲viewA,它將調用viewB。
  2. viewB然後將更改爲viewC。
  3. 最後,當我解僱我的viewC時,它將回到viewA。
  4. 所有的視圖都會有導航控制器。

而且,這裏是稍後在「viewB」,「viewC」上創建的導航按鈕。

SWRevealViewController *revealController = [self revealViewController]; 

[revealController panGestureRecognizer]; 
[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer]; 

UIBarButtonItem *revealButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"reveal-icon.png"] style:UIBarButtonItemStyleBordered target:revealController action:@selector(revealToggle:)]; 


self.navigationItem.leftBarButtonItem = revealButtonItem; 


//check if whether to use barTintColor instead of tintColor. (IOS difference) 
if (IS_OS_7_OR_LATER) { 
    // here you go with iOS 7 
    self.navigationController.navigationBar.barTintColor = UIColorFromRGB(0x808080); 
} 
else 
{ 
    self.navigationController.navigationBar.tintColor = UIColorFromRGB(0x808080); 
} 

self.navigationController.navigationBar.translucent = YES; 
//======================================================================================= 

它給出了實例化導航按鈕的視圖上的錯誤。 錯誤看起來是這樣的: *終止應用程序由於未捕獲的異常「NSInvalidArgumentException」,原因是:「* - [__ NSArrayM insertObject:atIndex:]:對象不能是零」

+0

所以現在你需要的是後解僱viewC,你需要回去viewA? –

+0

現在的問題是我甚至不能實例化導航按鈕,雖然我已經實例化欄。它給出錯誤,如「*** - [__ NSArrayM insertObject:atIndex:]:object can not be nil」,我不知道缺少什麼。 –

+0

是否可以,如果我編寫一個樣本,你將有3個屏幕,你將從1-> 2 - > 3 - > 1導航,所有這些都將有導航控制器。 –

回答

0

這是你如何呈現navigationcontroller在特定視圖 - 控制

LoginViewController *promotionViewController = [[LoginViewController alloc] init]; 
UINavigationController *navigationController = [[UINavigationController alloc]init]; 
[navigationController pushViewController:promotionViewController animated:YES]; 
[self presentViewController:navigationController animated:YES completion:nil]; 
+0

對不起,我英語不好,但我需要它導航到帶有導航控制器的LoginViewController。如果根據你的代碼,它會把我帶到一個完全黑屏的SWRevealViewController(在我的例子中)。 –

+0

我編輯了代碼請檢查 – Rose

+0

這有助於在實例化「viewB」頁面中的導航按鈕時仍然出錯。 –

0

試試下面的代碼來代替你的代碼:

UINavigationController * frontNavigationController =(id)revealController.frontViewController;

if (! [frontNavigationController.topViewController isKindOfClass:[CalibrateViewController class]]) { 
     CalibrateViewController *promotionViewController = [[CalibrateViewController alloc] init]; 
     UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:promotionViewController]; 
     [self.navigationController pushViewController:navigationController animated:YES]; 
    } 
    else { 
     [revealController revealToggle:self]; 
    } 
0

基本上Presentmodelviewcontroller沒有導航控制器,我們需要編寫它,請按照下面的代碼

NextViewController *ivc= [[NextViewController alloc]init]; // here you are allocation your next viewController 
UINavigationController *naviCtrl =[[UINavigationController alloc]initWithRootViewController: ivc]; // here you are allocation navigation controller for your next viewController 
[self presentViewController:naviCtrl animated:YES completion:nil]; // here you are presenting your next view controller 
+0

對不起,我的英語不好,但我需要它用導航控制器指向LoginViewController。如果根據你的代碼,它會把我帶到一個完全黑屏的SWRevealViewController(在我的例子中)。 –

+0

所以你只想回到你以前的視圖控制器? –

+0

我的回答是更新檢查一次 –

相關問題