Graphics Programs Reference
In-Depth Information
In your code, whenever a detail view controller was given to the split view controller, that
detail view controller was set as the split view controller's delegate. As the delegate, the
detail view controller will get a pointer to the
UIBarButtonItem
when rotating to por-
trait mode.
Since both
WebViewController
and
ChannelViewController
can be the del-
egate for a
UISplitViewController
, it's best to declare that they conform to the
UISplitViewControllerDelegate
protocol.
In
WebViewController.h
, add this declaration:
@interface WebViewController : UIViewController
<ListViewControllerDelegate
, UISplitViewControllerDelegate
>
And do the same in
ChannelViewController.h
.
@interface ChannelViewController : UITableViewController
<ListViewControllerDelegate
, UISplitViewControllerDelegate
>
Build and run the application. The behavior will be the same, but there won't be any
warnings.
In
WebViewController.m
, implement the following delegate method to place the bar
button item in the
WebViewController
's navigation item.
- (void)splitViewController:(UISplitViewController *)svc
willHideViewController:(UIViewController *)aViewController
withBarButtonItem:(UIBarButtonItem *)barButtonItem
forPopoverController:(UIPopoverController *)pc
{
// If this bar button item doesn't have a title, it won't appear at all.
[barButtonItem setTitle:@"List"];
// Take this bar button item and put it on the left side of our nav item.
[[self navigationItem] setLeftBarButtonItem:barButtonItem];
}
Notice that we explicitly set the title of the button. If the button doesn't have a title, it
won't appear at all. (If the master view controller's
navigationItem
has a title, then
the button will be automatically set to that title. )
Build and run the application. Rotate to portrait mode, and you will see the bar button
item appear on the left of the navigation bar. Tap that button, and the master view control-
ler's view will appear in a
UIPopoverController
.
This bar button item is why we always had you put the detail view controller inside a nav-
igation controller. You don't have to use a navigation controller to put a view controller in