繁体   English   中英

原型可重用tableview单元格渲染子视图效果不佳

[英]Prototype reusable tableview cell rendering subviews poorly

这是我遇到这个特殊问题的第二个项目。 今天早些时候,我通过情节提要建立了一个表格视图和原型单元。 我添加了带有标签编号的子视图,以便可以从cellforrowatindexpath委托方法中获取它们。 虽然当我运行应用程序时,子视图不在正确的位置。 我使用自动调整布局大小,并确保设置委托。 有人遇到过这个问题吗?

可能相关:有时,当我离开情节提要并返回时,子视图会更改其框架,以使它们平坦(高度= 0)或x随机更改为1,500。 不知道为什么,但这是在我也遇到问题的旧项目中发生的。 我的旧项目通过在cellforrowatindexpath方法中重置所有子视图的框架解决了该问题,但是我不喜欢将其作为合法解决方案。

编辑:这是一些代码和屏幕截图。

//MARK: - UITableview delegate
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    return 93.0
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 7;
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    var cell = tableView.dequeueReusableCellWithIdentifier("order") as? UITableViewCell
    println("cell: \(cell)")
    var cancel = cell?.viewWithTag(4) as UIButton
     var price = cell?.viewWithTag(3) as UILabel
     var date = cell?.viewWithTag(2) as UILabel
     var address = cell?.viewWithTag(1) as UILabel
    cancel.addTarget(self, action: "cancelOrder:", forControlEvents: UIControlEvents.TouchUpInside)

    return cell!
}

截图

我最近有这个问题。 对于自定义单元格中的内容视图,自动布局似乎是一个错误。

我所做的只是在awakeFromNib中,因为我的自定义单元格重置了自动调整大小蒙版,并且一切都按预期开始工作。

- (void) awakeFromNib
{
    self.contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM