当用户在主视图中选择一个单元格时,我正在尝试加载一个特定UITableViewController
的细节视图;UISplitViewController
但有一些问题。当我选择单元格时,它只显示一个没有表格视图控制器的空白窗口。
但是,如果我将 App Delegate 更改为仅加载UITableView
控制器而不使用UISplitViewController
它,它工作正常,所以我知道这是我编码方式的问题UISplitViewController.
视图层次结构:
UISplitViewController
-->
UINavigationController
--> UITableViewController (DetailViewController)
UINavigationController
--> UIViewController (ColorViewController)
用户选择一个单元格ColorViewController
,这应该改变DetailViewController.
在AppDelegate.m
:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.viewController = [[ViewController alloc] init];
self.window.rootViewController = [self.viewController splitViewController];
[self.window makeKeyAndVisible];
return YES;
}
在ViewController.m
:
- (UIViewController *) splitViewController {
// Create the navigation-run root view
ColorViewController *rootVC = [ColorViewController controller];
UINavigationController *rootNav = [[UINavigationController alloc] initWithRootViewController:rootVC];
// Create the navigation-run detail view
DetailViewController *detailVC = [DetailViewController controller];
UINavigationController *detailNav = [[UINavigationController alloc] initWithRootViewController:detailVC];
// Add both to the split view controller
svc = [[UISplitViewController alloc] init];
svc.viewControllers = [NSArray arrayWithObjects: rootNav, detailNav, nil];
svc.delegate = detailVC;
return svc;
}
在ColorViewController.m
:
@interface ColorViewController : UITableViewController
...
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UIViewController *controller = (UIViewController *)self.splitViewController.delegate;
TableViewController *tvc = [[TableViewController alloc] init];
[controller.view addSubview:tvc.view];
}
更改 Detail 视图的最佳方法是UISplitViewController
什么?我应该将替换视图添加到UIViewController
上面还是有更好的方法?也许这就是我的问题的原因?