Get the frame of UITableViewCellAccessoryDetailButton (which is nil)

丶灬走出姿态 提交于 2019-12-12 01:54:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!