获取 UITableViewCellAccessoryDe​​tailButton 的frame(为nil) [英] Get the frame of UITableViewCellAccessoryDetailButton (which is nil)

查看:68
本文介绍了获取 UITableViewCellAccessoryDe​​tailButton 的frame(为nil)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从 UITableViewCell 的附件视图中呈现一个弹出框.视图是默认的 UITableViewCellAccessoryDe​​tailButton.显然,附件视图是 nil,并且,根据 这个问题,这是一个预期的行为.我的问题是,即使accessoryView 属性为零,我如何获取附件的框架?

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?

推荐答案

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

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

这篇关于获取 UITableViewCellAccessoryDe​​tailButton 的frame(为nil)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆