0

我试图从 aUITableViewCell的附件视图中显示一个弹出窗口。视图是默认的UITableViewCellAccessoryDetailButton。显然,附件视图是nil,并且根据这个问题,这是一种预期的行为。我的问题是,即使accessoryView 属性为零,我如何获得配件的框架?

4

1 回答 1

2

您无需获取框架即可呈现弹出框。当你有一个附属视图时,单元格的 contentView 的宽度会变窄,所以它会在附属视图之前结束(如果你给 contentView 一个背景色,你可以看到这个)。您可以使用该宽度将弹出框定位在按钮的左侧,

-(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];
}
于 2015-03-14T00:44:24.623 回答