[英]UIActivityIndicatorView Inside TableView Cell
我正在尝试将Spinner添加到我在tableViewCell中定位的Like按钮。 但是问题是微调器显示在tableViewCell之外。
这就是我在cellForRowAtIndexPath
内部实现代码的方式
myspinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[myspinner setCenter:cell.like.center];
[cell.like addSubview:myspinner];
当我单击使用sender.tag
[myspinner startAnimating];
问题是微调器正在工作,但不是我想要的。 它显示在单元外部。
UPDATE
随着matt
的回答,它确实起作用。 我也改变了我的代码,如下所示。 内部选择器动作。 -(void) likeClicked:(UIButton*)sender
UIActivityIndicatorView *myspinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[myspinner setCenter: CGPointMake(CGRectGetMidX(sender.bounds),
CGRectGetMidY(sender.bounds))];
[sender addSubview:myspinner];
[myspinner startAnimating];
这种形式的代码:
[myspinner setCenter:cell.like.center];
...永远是不对的。 原因是myspinner.center
位于myspinner.center
视图的坐标中,即位于cell.like
坐标中。 但是cell.like.center
在其 cell.like.center
视图的坐标中。 因此,您正在将苹果与橙子进行比较:您是根据生活在完全不同的坐标系中的另一个点设置一个点。 那只能是偶然的。
您要做的是将myspinner.center
设置myspinner.center
视图bounds的中心。 这些值在同一坐标系中(此处为cell.like
的坐标系)。
[myspinner setCenter: CGPointMake(CGRectGetMidX(cell.like.bounds),
CGRectGetMidY(cell.like.bounds))];
或者您可能想使用单元格的内容视图来获取单元格的中心,
[myspinner setCenter:cell.contentview.center];
这也将起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.