UITableView内容视图的宽度与Container不匹配 [英] Width of UITableView content view does not match Container

查看:129
本文介绍了UITableView内容视图的宽度与Container不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在容器中嵌入了TableVC。在iPhone5上运行的Container的宽度为320。但是在TableView单元格中ContentView的宽度为600。如何使它们匹配? (+/-填充)。我错过约束了吗?我还在cellForRowAtIndexPath和自定义单元格子类中尝试了setNeedsLayout()和layoutSubViews(),但这似乎也不起作用。

I have a TableVC embedded in a Container. The width of the Container running on an iPhone5 is 320. However the width of the ContentView in the TableView cell is 600. How can I make them match? (+/- padding). Am I missing a constraint? I have also tried setNeedsLayout() and layoutSubViews() in cellForRowAtIndexPath and in the custom cells subclass, but this doesn't seem to work either.

在下面的图片中,我希望深灰色的宽度与浅灰色(+-填充)匹配

In the picture below, I want the width of the darkgrey to match the light grey (+- padding)

任何帮助,不胜感激.....

Any help much appreciated.....

 override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let cell = tableView.dequeueReusableCellWithIdentifier("EventCell") as! CustomResultsTVCell

    //        cell.setNeedsLayout()
    //        cell.layoutSubviews()
    //        cell.layoutIfNeeded()

    let barViewWidth = Float(cell.barView.frame.width)
    print("barview width is \(barViewWidth)")
// prints 584

    let contentViewWidth = cell.myContentView.frame.width
    print("contentView width is \(contentViewWidth)")
// prints 600

CustomCell类为

The CustomCell class is

import Foundation
import UIKit

class CustomResultsTVCell: UITableViewCell {

@IBOutlet weak var myContentView: UIView!
@IBOutlet weak var barView: UIView!

override func awakeFromNib() {
    super.awakeFromNib()

//        super.layoutSubviews()
//        setNeedsLayout()
//        layoutSubviews()
    layoutIfNeeded()
}

推荐答案

可以检查前约束和尾约束的属性。确保第一项和第二项均未选中相对于利润率

Can you check property of your leading and trailing constraints. Make sure it unchecked relative to margin for both first item and second item.

如果有帮助,请参阅随附的屏幕截图。

see attached screenshots if it helps you.

希望这将帮助您解决问题。

Hope this will help you to fix your issue.

这篇关于UITableView内容视图的宽度与Container不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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