derdida
derdida

Reputation: 14904

UIPopover Position in Cell

I would like to have my Popover right of my cell label, but it is currently on the left top position. How do I change it to get it to the right position?

I create my custom cell with:

var currentCell:CustomTableViewCell = tableView.cellForRowAtIndexPath(indexPath) as CustomTableViewCell;

And load the popover on table tap with:

var popoverContent = ModalTableViewController()
var nav = UINavigationController(rootViewController: popoverContent)
nav.modalPresentationStyle = UIModalPresentationStyle.Popover

var popover = nav.popoverPresentationController as UIPopoverPresentationController
popoverContent.preferredContentSize = CGSizeMake(500,400);
popover.delegate = self
popover.sourceView = self.view
popover.sourceRect = currentCell.labelCellTitle.bounds

the labelCellTitle is a custom label in my cell. I want to show the Popover with an arrow right to this label. What is wrong with my code? Any ideas?

Upvotes: 1

Views: 2140

Answers (1)

vignesh kumar
vignesh kumar

Reputation: 2330

As the popoverview needs to know the view upon which to show up and the frame of the rect area, you should use like below

var popover = nav.popoverPresentationController as UIPopoverPresentationController
popoverContent.preferredContentSize = CGSizeMake(500,400);
popover.delegate = self
popover.sourceView = currentCell.labelCellTitle.superView
popover.permittedArrowDirections = UIPopoverArrowDirectionRight
popover.sourceRect = currentCell.labelCellTitle.frame

Upvotes: 2

Related Questions