views:

510

answers:

2

I always try to present a popover from a cell inside a tableView this way:

[myPopover presentPopoverFromRect:cell.frame inView:self.tableView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

but I cannot use UIPopoverArrowDirectionRight or Left, because, depending on the position of the ipad (portrait or landscape), the popover appears someplace else.

Am I presenting the popover the right way?

PS: the table view is in the detailView of a splitView.

+1  A: 

The cell frame is going to be something like 0,0,width,size, i dont believe it will have its X and Y relative to the tableView...you want to use - (CGRect)rectForRowAtIndexPath:(NSIndexPath *)indexPath for this, this should return you the correct frame for the cell relative to the tableView...here is a link UITAbleView ref

Daniel
Hey! thanks for the answer.. but with the method you recommend I get the same CGrect, and I still have the problem with the popover's position. When the ipad is in portrait mode, the popover appears in the top left corner of the screen when I specify those arrow directions... it freaks me out!!! .. by the other hand,is it correct to present it from self.TableView? Thank you anyway
Omer
A: 

I had the same kind of problem, here's the workaround i used :

  • in my UITableViewCell, i added Actions (IBActions as i generate my cells from a NIB) for cell's specific buttons.
  • i then defined a CellActionDelegate protocol that mimics my actions selectors, to which i had my button (sender) and my cell (self)
  • then the detailViewController of my splitViewController implements this protocol, converting from the cell's to its coordinates...

here a example of code

In MyCustomTableViewCell.m :

   -(IBAction)displaySomeCellRelativePopover:(id)sender{
        //passes the actions to its delegate
        UIButton *button = (UIButton *)sender;
        [cellActionDelegate displaySomeCellRelativePopoverWithInformation:self.info
                                                               fromButton:button 
                                                                 fromCell:self];   
   }

and the, in MyDetailViewController.m :

-(void)displaySomeCellRelativePopoverWithInformation:(MyCellInformationClass *)info
                                          fromButton:(UIButton *)button 
                                            fromCell:(UIView *)cell{

UIPopoverController * popoverController = nil;

//create your own UIPopoverController the way you want

//Convert your button/view frame

CGRect buttonFrameInDetailView = [self.view convertRect:button.frame fromView:cell];

//present the popoverController
[popoverController presentPopoverFromRect:buttonFrameInDetailView
                               inView:self.view permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];]


//release objects created...
}

PS : Of course, the 'action' doesn't have to be a IBAction, and the frame from where the popover originates doesn't have to be a UIButton - a single UIView would be good :)

VinzzzBarto
Hey.. thanks, I'll give it a try.. this seems a smart workaround jeje
Omer