问题
I was trying to present a popover from a UITableViewCell
's accessoryView. The view is the default UITableViewCellAccessoryDetailButton
. Apparently the accessoryView is nil
, and, according to this question, this is an intended behavior. My question is, how do I get the frame of the accessory, even though the accessoryView property is nil?
回答1:
You don't need to get the frame to present the popover. When you have an accessory view, the width of the cell's contentView is made narrower so it ends just before the accessory view (you can see this if you give the contentView a background color). You can use that width to position your popover just to the left of the button,
-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
UIPopoverController *aPopover = [[UIPopoverController alloc] initWithContentViewController:[UIViewController new]];
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
CGRect popRect = CGRectMake(cell.frame.origin.x + cell.contentView.frame.size.width, cell.frame.size.height/2.0, 1, 1);
[aPopover presentPopoverFromRect:popRect inView:cell permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];
}
来源:https://stackoverflow.com/questions/29043950/get-the-frame-of-uitableviewcellaccessorydetailbutton-which-is-nil