Popover when starting in portrait


Is there a simple way to make the popover with the master view controller automatically display when starting up the application in portrait mode?



I’m not sure if there is a better way but you can emulate someone pressing the List button with
[barButtonItem.target performSelector:barButtonItem.action withObject:barButtonItem];

but it seems like the View hierarchy isn’t fully built in the obvious place to do this splitViewController:willHideViewController:withBarButtonItem:forPopoverController:
and it generates an error

However if you add a delay (1 second works for me) then it seems to get round this.


[code]- (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];

// Emulate the user pressing the List button 1 second after this method triggers.
[barButtonItem.target performSelector:barButtonItem.action withObject:barButtonItem afterDelay:1.0];



I think that solution will open the button every time it appears, not just on startup.

My solution would be:
When starting the application, the splitViewController:willHideViewController:… is invoked before the view is fully loaded.

In WebViewController.[hm],
Add a BOOL buttonSetOnStart to the class, and then in the …willHideViewController… method check if the view is loaded

if (![self isViewLoaded]) buttonSetOnStart = YES;

then, in viewDidAppear, invoke the button if it was set on start:

if (buttonSetOnStart)
    UIBarButtonItem *barButtonItem = [[self navigationItem] leftBarButtonItem];
    [barButtonItem.target performSelector:barButtonItem.action withObject:barButtonItem];
buttonSetOnStart = NO;

– Kurt