2013-10-04 82 views
0

我有一個帶有3個視圖控制器和一個導航視圖控制器的標籤欄控制器。 該導航視圖控制器具有表格視圖控制器和詳細視圖。加載導航視圖控制器中的特定視圖

在我的第一個視圖控制器(第一個選項卡)中有三個按鈕。我想要第一個按鈕在導航控制器中加載詳細視圖。 (如參見下圖)

Storyboard

我怎樣才能做到這一點?

我曾嘗試調用在LocationsTableViewController中執行segue的方法,但是這給了我錯誤「Receiver()沒有標識符'addLocation'」。雖然segue「addLocation」當然存在。

法StartViewController連接到按鈕:

- (IBAction)addLocationView:(id)sender { 

    LocationsTableViewController *LTVC = [[LocationsTableViewController alloc] init]; 
    [LTVC addLocation]; 

} 

LocationsTableViewController:

-(void)addLocation 
{ 
    [self performSegueWithIdentifier: @"addLocation" sender: self]; 
} 

回答

0

你 「addLocation」 賽格瑞是從位置表視圖控制器使用添加位置視圖控制器,所以SEGUE存在在LocationsTableViewController上。那是對的。但是,如果您當前的視圖控制器不是LocationsTableViewController,則調用該segue是沒有意義的。

您有幾種選擇:

  1. 故事板選項#1:請從StartViewController到AddLocationViewController新SEGUE,並在addLocationView:執行SEGUE。
  2. 故事板選項#2:從按鈕新增一個Segue到AddLocationViewController,並刪除您的IBAction。故事板會在按鈕被點擊時自動調用該繼續。
  3. Programatic選項:實例化一個新的AddLocationViewController並將其推入導航堆棧:[self.navigationController pushViewController:[[AddLocationViewController alloc] init] animated:YES]
+0

嗨, 我已經嘗試過選項1和2,但只有視圖出現,沒有tabbar和導航欄。 由於self.navigationController,選項3不起作用。 Startview不是導航控制器。我試過 LocationsViewController * LVC = [[LocationsViewController alloc] init]; [self presentViewController:LVC animated:YES completion:Nil]; [LVC.navigationController pushViewController:[[AddLocationViewController alloc] init] animated:YES]; 但這裏只顯示一個空的tabbar。 – Drew