3
votes

We have a UISplitViewController and under condition X, we need to display a UIPopover from one of the UIBarButtonItem of the Master view.

Supposedly, in order to have the frame/layout correct, we do this code from the Master view controller's viewDidLoad event. Somehow the first time the UISplitViewController is shown, the frame of the Master is 1024x724 whereas we'd expect it to be 320x724. As a result, the call to [UIPopover presentFromBarButtonItem:] uses a wrong referential and since it's a right BarButtonItem, the popover appears all the way to the right of the screen (at about x = 980px)

If we delay the displaying by a split second (via a Timer/delay, sooo dirty) then it's all fine.

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    CGRect masterViewFrame = self.view.frame;
    NSLog(@"Master View Frame: %@", NSStringFromCGRect(masterViewFrame));    

    if (someCondition) {
        [self showPopover:self.theBarButton];
    }
}

The NSLog here shows 1024x724 @ 0x0

Thoughts?

1
Are you placing it before or after -viewDidLoad? Can you put it in viewWillAppear or viewDidAppear?jrtc27
Added code sample in the original question. I'm essentially making the call at the end of viewDidAppearOli
How are you creating the split view?jrtc27
The whole thing is within a StoryboardOli

1 Answers

0
votes

You can do something like this:

//Check if you really are in a UISplitViewController
CGRect frame = self.view.frame; //this is the default value
if(self.splitViewController)
{ 
   //you are trying to access the frame of this VC's view via the splitViewController
   //this should return the correct size    
   frame = [[[self.splitViewController.viewControllers objectAtIndex:0] view] frame];
}