Show a UIPopoverController from a detail disclosure button in a UITableViewCell

后端 未结 1 2023
滥情空心
滥情空心 2021-02-06 17:13

I am creating an application for the iPad, and I want to show an UIPopoverController with an arrow pointing to the detail disclosure button for the row it belongs t

相关标签:
1条回答
  • 2021-02-06 17:44

    To do what you want, you need an accessoryView and setting the accessoryType does not create one. However, it will work if you create a button and set it as the cell.accessoryView.

    Create and set the accessoryView when the cell is created:

        ...
        UIButton *disclosureButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        [disclosureButton addTarget:self action:@selector(discloseDetails:) forControlEvents:UIControlEventTouchUpInside];
        cell.accessoryView = disclosureButton;
        ...
    

    Replace tableView:accessoryButtonTappedForRowWithIndexPath: with discloseDetails:. This looks much like what you have before so I've only put the changes below:

    - (void) discloseDetails:(UIButton *)sender {
        ...
        UITableViewCell *cell = (UITableViewCell *) sender.superview;
        NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];  // if needed
        [addFeedPopup presentPopoverFromRect:cell.accessoryView.bounds inView:cell.accessoryView permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
        ...
    }
    

    If you don't need the cell, it can be made even simpler:

    - (void) discloseDetails:(UIButton *)sender {
        ...
        [addFeedPopup presentPopoverFromRect:sender.bounds inView:sender permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
        ...
    }
    

    Here's what it looks like

    enter image description here

    0 讨论(0)
提交回复
热议问题