werner77/WEPopover — Issue #26: presentPopoverFromBarButtonItem: not working properly in iOS5
Author: Giebler
Created: 2011-11-15 19:02:51+00:00
State: open

I traced the problem down to the frameInView code in UIBarButtonItem+WEPopover.m

First, I got an error when running due to the location of the following code:

if (!hasCustomView) {
[self setCustomView:nil];
}

Since this code occurred before UIView *button = [parentView.subviews objectAtIndex:indexOfView]; and the newly created view was the last object in the array, the indexOfView parameter exceeded the bounds of the array.

I moved the code shown above to after the array is referenced and that eliminated the error.

However, frameInView doesn't return the proper CGRect for the button, which messes up the position of the arrow and to make matters worse, the button completely disappears from the app once pressed!

I haven't found a proper way to get the correct frame, so I ended up using presentPopoverFromRect: using two different CGRect's - one for portrait and one for landscape.

Hopefully this will save you time and effort if you plan on using presentPopoverFromBarButtonItem: