0
votes

I am implementing a split view controller programmatically for iPad. This is the code I am using in didFinishLaunching:

self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.

MasterViewController *masterViewController = [[MasterViewController alloc] init];
UINavigationController *masterNavigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];

DetailedNewsViewController *detailViewController = [[DetailedNewsViewController alloc] init];
UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController];

masterViewController.detailViewController = detailViewController;

self.splitViewController = [[UISplitViewController alloc] init];
self.splitViewController.delegate = detailViewController;

self.splitViewController.viewControllers = @[masterNavigationController, detailNavigationController];

self.window.rootViewController = self.splitViewController;
[self.window makeKeyAndVisible];

but when I run this code. The MasterView is showing correctly, it is a TableViewController. But the DetailView isn't showing, its just a black screen, i tried writing the variables used in the DetailView programmatically and adding them to the view & it worked.

Why for the MasterViewController it is taking it directly from the storyboard whereas for the DetailViewController I have to code it manually ?, and it is really tough to do it manually I have already done everything in the storyboard

Thank you.

1

1 Answers

0
votes

No need for masterViewController.detailViewController = detailViewController;, rather, use self.splitViewController.viewControllers = [NSArray arrayWithObjects: masterNavigationController, detailNavigationController,nil];