我的项目也遇到了这个问题。我使用以下代码完成了此操作
您需要做的是,当您点击根视图控制器的 tableview 的任何单元格时,您必须加载适当的视图控制器。
您必须在根视图控制器的 tableview 的 tableViewDidSelectRowaAtIndexPath 部分编写以下代码。
- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//Load previous controllers array.
NSMutableArray *viewControllerArray=[[NSMutableArray alloc] initWithArray:splitViewController.viewControllers];
//Remove last Detail View controller Object.
[viewControllerArray removeLastObject];
// Check appropirate row value.
if (indexPath.row == 0) {
// Add new Detail controller in your array ...
FirstViewController *fvc=[[[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil] autorelease];
[viewControllerArray addObject:fvc];
}
else if (indexPath.row == 1) {
// Add new Detail controller in your array ...
SecondViewController *svc=[[[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil] autorelease];
[viewControllerArray addObject:svc];
}
// And so on..
// Set New View Controllers of SplitViewController
[splitViewController setViewControllers:viewControllerArray];
[viewControllerArray release];
}
我这样做了,它奏效了。我希望它会有所帮助。