1

嘗試將新視圖控制器推送到現有導航控制器時遇到問題。從彈出窗口中將UIViewController推送到UINavigationController

我試圖讓UIPopoverController出現在推動導航UIBarButtonItem,並從該「下拉」選擇一個菜單點,將關聯的視圖控制器推到「主」導航控制器。

我試過以下,它給出了一種模式。但我希望推送的視圖。 enter image description here 如果選擇push而不是modal,結果如下。

enter image description here 我也試圖使從我試過下面的代碼定製UITableViewController(在酥料餅):

-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; 
    UINavigationController *dash = [storyboard instantiateViewControllerWithIdentifier:@"dash_nav"]; 
    UIViewController *students = [storyboard instantiateViewControllerWithIdentifier:@"students"]; 

    if (indexPath.row == 0) { 
     [dash pushViewController:students animated:YES]; 
//  [[dash navigationController] presentViewController:students animated:YES completion:nil]; 
    } 
    NSLog(@"%@", [dash title]); 
    NSLog(@"index = %i", indexPath.row); 
} 

有沒有辦法做什麼,我試圖完成?

+0

兩件事情..首先,你是如何在故事板中製作這些小型tableView的?其次,如果你使用master-detail,你可以使用*替換*而不是* push * – Marc

回答

0

此代碼:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; 
UINavigationController *dash = [storyboard instantiateViewControllerWithIdentifier:@"dash_nav"]; 
UIViewController *students = [storyboard instantiateViewControllerWithIdentifier:@"students"]; 

創造了太多新的實例。您應該使用現有的故事板(self. storyboard)和現有的導航控制器。導航控制器需要傳遞給表視圖控制器(您應該使用,因爲故事板沒有所需的信息)。我們將在桌面視圖控制器上調用originatingNavigationController,一個新的@property

當segue觸發顯示彈出窗口時,將導航控制器引用設置到目標視圖控制器(表格視圖)中。

然後,在didSelectRowAtIndexPath:方法,你剛剛實例化students VC和推:

UIViewController *students = [self.storyboard instantiateViewControllerWithIdentifier:@"students"]; 
[self.originatingNavigationController pushViewController:students animated:YES]; 

,然後將表視圖控制器應駁回本身(及其酥料餅)。

+0

這正是我所需要的!謝謝。 – mrjensen

相關問題