Width of UITableView content view does not match Container

徘徊边缘 提交于 2019-12-11 06:36:29

问题


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

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()
}


回答1:


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.



来源:https://stackoverflow.com/questions/38383143/width-of-uitableview-content-view-does-not-match-container

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!