Graphics Programs Reference
In-Depth Information
UIViewController has a nibName that you pass in the initializer message. (If you
pass nil , the nibName is effectively the name of the class.) When a view controller
goes to load its view, it loads the XIB file that matches its nibName . However, if the ap-
plication is running on an iPad, it first checks for a matching XIB file suffixed with
~ipad . If there is one, it loads that XIB file instead.
At this point, we're not focusing on the appearance of the DetailViewController 's
view, so we have a third option: leave it as it is. But let's do something about the blind-
ingly white background. In DetailViewController 's viewDidLoad method, the
background color of the view is set to be the groupTableViewBackgroundColor
color. This color is not available on the iPad, which is why you get the all-white back-
ground instead. So when the application is running on an iPad, let's set the color to closely
match the background color of ItemsViewController 's view.
Determining device family
First, we need to check what type of device the application is running on. The object to
ask is the UIDevice singleton. You get this object by sending the class method cur-
rentDevice to the UIDevice class. Then you can check the value of its userIn-
terfaceIdiom property. At this time, there are only two possible values: UIUserIn-
terfaceIdiomPad (for an iPad) and UIUserInterfaceIdiomPhone (for an
iPhone or an iPod touch).
In DetailViewController.m , modify viewDidLoad .
- (void)viewDidLoad
{
[super viewDidLoad];
[[self view] setBackgroundColor:[UIColor groupTableViewBackgroundColor]];
UIColor *clr = nil;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
clr = [UIColor colorWithRed:0.875 green:0.88 blue:0.91 alpha:1];
} else {
clr = [UIColor groupTableViewBackgroundColor];
}
[[self view] setBackgroundColor:clr];
}
Build and run the application on the iPad simulator or on an iPad. Navigate to the De-
tailViewController and sigh in relief at the much nicer background color.
Search WWH ::




Custom Search