Graphics Programs Reference
In-Depth Information
Splitting Up Nerdfeed
Creating a UISplitViewController is simple since you have already learned about
navigation controllers and tab bar controllers. When you initialize a split view controller,
you pass it an array of view controllers just like with a tab bar controller. However, a split
view controller's array is limited to two view controllers: a master view controller and a de-
tail view controller. The order of the view controllers in the array determines their roles in
the split view; the first entry is the master view controller, and the second is the detail view
controller.
Open Nerdfeed.xcodeproj in Xcode . Then, open NerdfeedAppDelegate.m .
In application:didFinishLaunchingWithOptions: , check if the device is an
iPad before instantiating a UISplitViewController . The UISplitViewCon-
troller class does not exist on the iPhone, and trying to create an instance of
UISplitViewController will cause an exception to be thrown.
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
ListViewController *lvc =
[[ListViewController alloc] initWithStyle:UITableViewStylePlain];
UINavigationController *masterNav =
[[UINavigationController alloc] initWithRootViewController:lvc];
WebViewController *wvc = [[WebViewController alloc] init];
[lvc setWebViewController:wvc];
[[self window] setRootViewController:masterNav];
// Check to make sure we're running on the iPad.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
// webViewController must be in navigation controller, you'll see why later.
UINavigationController *detailNav =
[[UINavigationController alloc] initWithRootViewController:wvc];
NSArray *vcs = [NSArray arrayWithObjects:masterNav, detailNav, nil];
UISplitViewController *svc = [[UISplitViewController alloc] init];
// Set the delegate of the split view controller to the detail VC
// We'll need this later - ignore the warning for now
[svc setDelegate:wvc];
[svc setViewControllers:vcs];
// Set the root view controller of the window to the split view controller
[[self window] setRootViewController:svc];
} else {
// On non-iPad devices, go with the old version and just add the
// single nav controller to the window
Search WWH ::




Custom Search