How to correctly present a popover from a UITableViewCell with UIPopoverArrowDirectionRight or UIPopoverArrowDirectionLeft

后端 未结 11 800
失恋的感觉
失恋的感觉 2020-12-02 15:30

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

[myPopover presentPopoverFromRect:cell.frame inView:self.tableView permittedArrowD         


        
11条回答
  •  一整个雨季
    2020-12-02 16:18

    I came across this problem today, and I've found a simpler solution.
    When instantiating the popover, you need specify the cell's content view:

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        UIViewController *aViewController = [[UIViewController alloc] init];
        // initialize view here
    
        UIPopoverController *popoverController = [[UIPopoverController alloc] 
            initWithContentViewController:aViewController];
        popoverController.popoverContentSize = CGSizeMake(320, 416);
        UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
        [popoverController presentPopoverFromRect:cell.bounds inView:cell.contentView 
            permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    
        [aView release];
        // release popover in 'popoverControllerDidDismissPopover:' method
    }
    

提交回复
热议问题