Ashraf
Ashraf

Reputation: 175

UIPopoverController over UITableViewCell

I'd like to programmatically select a row in a table view then present my popover and let the arrow points to the cell.

This code works fine when the table has no scrolling, for scrolling table view the popover arrow is positioned incorrectly.

[self.EventsTableView selectRowAtIndexPath:indexPath 
                                  animated:YES 
                            scrollPosition:UITableViewScrollPositionMiddle];

[popoverController presentPopoverFromRect:CGRectOffset(cell.frame, 0, cell.frame.size.height + self.EventsTableView.contentOffset) 
                                   inView:self.view      
                 permittedArrowDirections:UIPopoverArrowDirectionLeft 
                                 animated:YES];

Thanks for any help

Upvotes: 3

Views: 4712

Answers (2)

mannyvw
mannyvw

Reputation: 83

Above method didn’t seem to work for me when once the user scrolls the list down. Finding the cell position relative to the scrolled amount was the trick.

CGRect rect = [tableView convertRect:[tableView rectForRowAtIndexPath:indexPath]
    toView:tableView]; 

[popoverController presentPopoverFromRect:rect
    inView:tableView
    permittedArrowDirections:UIPopoverArrowDirectionAny
    animated:YES];

Upvotes: 5

David Beck
David Beck

Reputation: 10159

You should pass the cell as the view. Most likely you will want to pass the cell's bounds (cell.bounds, not cell.frame) for the rect.

Upvotes: 6

Related Questions