Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UISplitViewController not showing popup button when launching portrait

I am doing an iPad app based on a UISplitViewController. I have a little problem with the toobar button when my app launched in potrait. The button to show the popover is not displayed. However when I rotate my iPad into landscape and then back to portrait, the button shows !

It looks like the following method is not called on launch (this is were I have the code showing the button):

- (void)splitViewController:(UISplitViewController *)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController: (UIPopoverController *)pc

This method is not called when the app launches but only when there is a rotation. What is even stranger is that I made a test app using Xcode UISplitViewController template + core data (which is similar to the app I am working on, and is the template I used to make this app). On the test app on which I have not made a single line of code, the button shows when I launch my app in portrait mode and the method above is also called upon launching, as opposed to my other app. Does anyone had a similar problem ?

Finally, it is not very clear from apple documentation whether this method is supposed to be called when a UISplitViewController is first shown: http://developer.apple.com/library/ios/#documentation/uikit/reference/UISplitViewControllerDelegate_protocol/Reference/Reference.html%23//apple_ref/doc/uid/TP40009454

like image 375
rpechayr Avatar asked May 02 '11 09:05

rpechayr


2 Answers

"Kshitiz" has the right concept. first I set the self.splitviewController.delegate = self in the viewDidLoad method, which it is a bit late to set this delegation. So, I tried to set the delegation in earlier stage which is awakeFromNib method. Then it works well.

So, the problem is after view already loaded by viewDidLoad, then the delegation will not work, it will work some time after some activities (such as rotate the iPad). So the earlier stage than viewDidLoad is awakeFromNib.

Here is the code that works:

- (void) awakeFromNib{
    [super awakeFromNib];
    self.splitViewController.delegate = self;
}
like image 99
victorxiv Avatar answered Sep 30 '22 03:09

victorxiv


Have you set a splitviewcontroller delegate? Generally the problem arises when delegate is not set.

like image 36
Kshitiz Ghimire Avatar answered Sep 30 '22 04:09

Kshitiz Ghimire