Shadowman
Shadowman

Reputation: 12079

UIPopoverControl on UIButton inside UICollectionViewCell?

I have a UICollectionView, in which I have numerous UICollectionViewCells that each have a UIButton within them. I would like to display a UIPopoverController each time a user presses on one of these UIButton. However, when I do, the position of the UIPopoverController is nowhere near correct. My guess is that it's due to a translation issue in the CGRect I'm using, but I can't for the life of me figure out how to correct it. Inside my selector that is called when the UIButton is pressed, I have something like this...

UIButton *detailsButton = (UIButton *)sender;
[self.popoverController presentPopoverFromRect:detailsButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

When I do this, however, it appears to be positioned at the same place every time, regardless of the position of the UIButton and UICollectionViewCell within the UICollectionView. Can someone give me some pointers as to how I can translate the position of the UIButton within the entirety of the UICollectionView? I suppose I need the absolute position of the detailsButton, but am at a loss as to how to get it.

Thanks for any help you can give!

Upvotes: 1

Views: 203

Answers (1)

Neal Ehardt
Neal Ehardt

Reputation: 10954

Views have coordinates relative to their superview, not relative to the screen. So if all your cells are identical, detailsButton.frame will be identical for all the buttons.

Try changing the inView: parameter.

[self.popoverController presentPopoverFromRect:detailsButton.frame inView:detailsButton.superview permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

Upvotes: 1

Related Questions