2011-11-01 32 views
0

我已經採取了基於標準的iPad SplitViewerController模板的項目和實施遞歸向下鑽取導航功能的任何數量的級別如下:iPad的SplitViewController遞歸向下鑽取 - 訪問DetailViewController

首先我創建了一個新的視圖控制器(命名NavItemController),我彈出到控制器堆疊在RootViewController的的didSelectRowAtIndexPath方法方法如下:

NavItemController *navItemController = [[NavItemController alloc] initWithNibName:@"NavItemController" bundle:[NSBundle mainBundle]]; 
navItemController.title = catalogue.name; 
[[self navigationController] pushViewController:navItemController animated:YES]; 

我然後使用此視圖控制器對所有導航上下我的樹結構(因此RootViewController的現在僅用於顯示最初的根級別導航即沒有父母的項目)。

這一切都很好。

現在我正在嘗試更新詳細視圖(detailViewDescriptionLabel)上的標籤,當我在NavItemController中選擇一個項目時。要做到這一點,我首先增加了一出口我NavItemController:

@property (nonatomic, strong) IBOutlet DetailViewController *detailViewController; 

,並從圖書館到對象列表中添加一個視圖控制器,改變其類DetailViewController和掛鉤的出口在InterfaceBuilder中配置它,我在File's Owner下找到。

在這一點上,如果我一步一步通過我的代碼,我發現它正確設置我的詳細信息視圖中的detailItem到在我的NavController中選擇的對象 - 它似乎正確地將detailDescriptionLabel.text值設置爲從此detailItem 。然而,這並不反映在用戶界面(它仍然工作,如果我從RootViewController這樣做)。

我在猜測,我沒有正確地勾住某個東西,或者錯過了某個步驟 - 我(顯然)對iOS來說很新 - 任何指針都會被讚賞。

回答

0

我最終通過使用iOS 5和Master Detail模板從頭創建我的項目來解決我的問題。我還選擇使用故事板功能。

我能夠爲我的遞歸導航使用MasterViewController(與之前模板中的RootViewController相同),即我不需要創建單獨的視圖控制器。

在MasterViewController didSelectRowAtIndexPath方法方法的代碼結束了:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSManagedObject *selectedObject = [[self fetchedResultsController] objectAtIndexPath:indexPath]; 
    self.detailViewController.detailItem = selectedObject; 

    NavItem *navItem = ((NavItem *) selectedObject); 
    Catalogue *catalogue = nil; 
    Document *document = nil; 

    if (navItem.catalogue != nil) // Load child catalogues and documents 
    { 
     catalogue = [navItem catalogue]; 
     DataLoader *dataLoader =[(AppDelegate *)[[UIApplication sharedApplication] delegate] dataLoader]; 
     [dataLoader drillDownIntoNavItems:catalogue]; 
     UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]]; 
     MasterViewController *controller = [storyBoard instantiateViewControllerWithIdentifier:@"master"]; 
     controller.managedObjectContext = self.managedObjectContext; 
     controller.title = catalogue.name; 

     [[self navigationController] pushViewController:controller animated:YES]; 
    } 
    else if (navItem.document != nil) // Load attachments 
    { 
     document = [navItem document]; 
     DataLoader *dataLoader =[(AppDelegate *)[[UIApplication sharedApplication] delegate] dataLoader]; 
     [dataLoader drillDownIntoNavItems:document]; 
     UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]]; 
     MasterViewController *controller = [storyBoard instantiateViewControllerWithIdentifier:@"master"]; 
     controller.managedObjectContext = self.managedObjectContext; 
     controller.title = document.name; 
     [[self navigationController] pushViewController:controller animated:YES]; 

     // Display document in detail viewer 
    } 

    else // attachment 
    { 
     // Display attachment in popover 
    } 
} 

同樣重要的是viewWillDisappear方法在MasterViewController:

- (void)viewWillDisappear:(BOOL)animated 
{ 
    if ([self.navigationController.viewControllers indexOfObject:self]==NSNotFound) { 
     // back button was pressed. We know this is true because self is no longer 
     // in the navigation stack. 
     DataLoader *dataLoader =[(AppDelegate *)[[UIApplication sharedApplication] delegate] dataLoader]; 
     [dataLoader drillUpIntoNavItems]; 
    } 

    [super viewWillDisappear:animated]; 
}