开发者

Odd behavior when showing UIPopoverController

开发者 https://www.devze.com 2023-01-16 02:59 出处:网络
In my iPad app, I save the state (visible/not visible) of a popover. So, during the launch of the app I initialize the UIPopoverController and tell it to show itself by using presentPopoverFromBarButt

In my iPad app, I save the state (visible/not visible) of a popover. So, during the launch of the app I initialize the UIPopoverController and tell it to show itself by using presentPopoverFromBarButtonItem:permittedArrowDirections:animated:. For the first argument (UIBarButtonItem), I use self.navigationItem.rightBarButtonItem. However, the popover keeps showing up on the left side of the screen (and not underneath the targeted button).

After the app is launched, the behavior is as expected. Any suggestions how to solve this?

For your information, I initialize the rightBarButtonItem and assign it to the navigationItem in the viewDidLoad method and before asking the popover to present itself. I have tried to call the popover in viewWillAppear and viewDidLoad, but the effect is the same.

My best alternative is to use presentPopoverFromRect:inView:permittedArrowDirections:a开发者_如何学Pythonnimated: instead and "guess" the position depending on the orientation of the device.

Update: when I rotate the iPad, the popover does jump to the correct position. It seems that the barButtonItem's position is only determined at the last minute and after I ask my popover to present itself.


In situations like these where timing appears to be important I found that the trick of postponing an action until the next iteration of the run loop helps. If developing for iOS 4.0+, this can be easily achieved with GDC:

// call from viewDidAppear:
dispatch_async(dispatch_get_main_queue(), ^{
    // call presentPopoverFromBarButtonItem:permittedArrowDirections:animated: here
});
0

精彩评论

暂无评论...
验证码 换一张
取 消