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];
}