在UITableViewCell中添加为子视图后,自定义UIView(.xib)会自动更改帧

时间:2014-10-11 09:43:16

标签: ios iphone uitableview uiview

由于要求,我使用.xib制作了自定义UIView。问题是当我分配,初始化uiview时,框架是可以的,但是当我将视图作为子视图添加到UITableViewCell.contentView时,我的自定义视图的框架发生了显着变化。我甚至试图在添加为子视图之后强制执行该框架,但没有任何帮助。

我正在使用带有autolayout的storyBoard。当我在自定义视图中设置约束并删除所有约束时,问题仍然存在。

提前致谢。

1 个答案:

答案 0 :(得分:0)

因此,您的问题是,在将视图添加到单元格的内容视图中时,您不会更改行的高度。以下是高度方法和您需要实施的更改: -

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
  if((indexPath.row==3 && rowSelected))  //You need to put condition check in which you need to see if that particular row is selected or not.
  //Then a flag for checking if view is added or not to it's contentView.
  //If both condition true then you need to provide a new height to that particular cell.

    return 220;  //120 height of your cell + 100 height of your view.
  else
    return 120;
}
相关问题