【问题标题】:UIActivityIndicatorView Inside TableView CellUIActivityIndi​​catorView 在 TableView 单元格内
【发布时间】:2016-03-07 03:36:04
【问题描述】:

我正在尝试将 Spinner 添加到我放置在 tableViewCell 中的 Like 按钮。但问题是微调器显示在 tableViewCell 之外。

这就是我在 cellForRowAtIndexPath 中实现代码的方式

myspinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];

[myspinner setCenter:cell.like.center];
[cell.like addSubview:myspinner];

当我点击使用sender.tag

[myspinner startAnimating];

问题是微调器工作但不是我想要的。它显示在单元格外。

更新

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

【问题讨论】:

    标签: ios objective-c uitableview uiactivityindicatorview


    【解决方案1】:

    这种形式的代码:

    [myspinner setCenter:cell.like.center];
    

    ...永远不对。原因是myspinner.center 在其父视图的坐标中——即在cell.like 坐标中。但cell.like.center 位于 超级视图的坐标中。因此,您将苹果与橙子进行比较:您根据位于完全不同坐标系中的另一个点来设置一个点。这只能是偶然的。

    您要做的是将myspinner.center 设置为其父视图边界 的中心。这些值在相同坐标系中(这里是cell.like的坐标系)。

    [myspinner setCenter: CGPointMake(CGRectGetMidX(cell.like.bounds),
                                 CGRectGetMidY(cell.like.bounds))];
    

    【讨论】:

    • 感谢它确实有效。而不是使用cell.like.bounds.,当我点击喜欢按钮时,我在我的动作选择器中使用了sender.bounds
    • 当然,听起来不错。关键是要了解坐标系的性质。
    • 是的,我明白了。再次感谢。 :)
    【解决方案2】:

    或者您可能想使用单元格的内容视图来获取单元格的中心,

    [myspinner setCenter:cell.contentview.center];
    

    这也可以。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多