Graphics Programs Reference
In-Depth Information
While XIB files are typically used to create the view for a view controller (for example,
TimeViewController.xib ), you've now seen that a XIB file can be used any time
you wish to archive view objects. In addition, any object can load a XIB file manually by
sending the message loadNibNamed:owner:options: to the application bundle.
UIViewController 's default XIB loading behavior uses the same code. The only dif-
ference is that it connects its view outlet to the view object in the XIB file. Imagine what
the default implementation of loadView for UIViewController probably looks
like:
- (void)loadView
{
// If a nibName was passed to initWithNibName:bundle:
if ([self nibName]) {
// Load that nib file, with ourselves as the file's owner, thus connecting
// the view outlet to the view in the nib
[[NSBundle mainBundle] loadNibNamed:[self nibName] owner:self options:nil];
}
else {
// What is the name of this class?
NSString *className = NSStringFromClass([self class]);
// What's the full path of the nib file?
NSString *nibPath = [[NSBundle mainBundle] pathForResource:className
ofType:@"nib"];
// If there really is a nib file at that path, load it
if ([[NSFileManager defaultManager] fileExistsAtPath:nibPath]) {
[[NSBundle mainBundle] loadNibNamed:className owner:self options:nil];
}
else {
// If there is no nib, just create a blank UIView
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
[self setView:view];
}
}
}
Now let's implement the toggleEditingMode: method. We could toggle the edit-
ing property of UITableView directly. However, UITableViewController also
has an editing property. A UITableViewController instance automatically sets
the editing property of its table view to match its own editing property. Which one
should we set? Follow the Model-View-Controller pattern: talk to the controller and let
the controller talk to the view.
Search WWH ::




Custom Search