简体   繁体   中英

DetailView not created in UISplitView

I want to create UISplitView programmatically after pressing a button in a view. For UISplitView, I have two view controllers called as MyTableViewController and MyDetailViewController . This is what I am doing in the action of the button:

UISplitViewController* splitVC = [[UISplitViewController alloc] init];
MyTableViewController* firstVC = [[MyTableViewController alloc] init];
MyDetailViewController* secondVC = [[MyDetailViewController alloc] init];

UINavigationController *leftNavController = [[UINavigationController alloc] init];
[leftNavController pushViewController:firstVC animated:NO];

splitVC.viewControllers = [NSArray arrayWithObjects:leftNavController, secondVC, nil];

AppDelegate * appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate.window setRootViewController:splitVC];

But secondVC (the detail view) doesn't show up. It is just black. Though, the firstVC (the table view) shows up as it should be. What could be the reason?

You should take a look at using [self.storyboard instantiateViewControllerWithIdentifier:@"DetailViewIdentifier"] , and set an identifier for the view controller in your storyboard. Calling init on a view controller doesn't reference the storyboard you have created, so you need to instead pull the view controller out of the storyboard. The table view worked because its layout is programmed into the UITableViewController class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM