Search code examples
iosuitableviewuipopovercontrolleraccessoryview

Table view with multiple cell accessory buttons should open and close popover with one tap


My question is similar to Close Popover and open new one with one tap. In my case I have an UITableView with multiple rows. Each row has an UITableViewCellAccessoryDetailDisclosureButton. When the blue info button is pressed a popover is presented to the user. Now the user wants to select another info button in another row (if the popover doesn't hide it). Currently the user has to tap twice:

  • One for dismissing the current popover
  • One for showing the new popover

I want that this can be done with one tap if the blue info button is visible. From the linked SO question the solution should be using

passthroughViews

I tried to use the table views controller view but it should be only the accessory view. In addition, a tap on an empty table view cell doesn't dismiss the popover anymore. If a cell with data is tapped one has to dismiss the popover manually in code in didSelectRowAtIndexPath.

How can I get all accessory views of my table?


Solution

  • Something like this:

    NSMutableArray *passthroughViews = [[NSMutableArray alloc] init];
    for (UITableViewCell *cell in myTableView.visibleCells) {
        [passthroughViews addObject:cell.accessoryView];
    }
    [myPopover setPassthroughViews:passthroughViews];
    

    Note, this means you will have to add your own accessory views to the cells instead of using the default accessories.