2015-08-28 90 views
0

我一直在试图让一个非常基本的自我尺寸的UITableViewCell出现在表中,但自定义单元甚至不会显示出来。自定义UITableViewCell永远不会出现AutoLayout自我尺寸

我正在使用iOS 8,而不用担心实现委托高度函数的结果。我使用默认的UITableViewCell时,我的UITableView的代码工作,所以我假设问题出在我的UITableViewCell中,但它很简单,我不知道如何可能是这种情况。

下面是其约束的单元格(在内容视图 - 我试图调整优先级升/降,但一切都没有帮助): Very bright label

这里是在TableViewController笔尖加载代码:

[submissionTable registerNib: [UINib nibWithNibName:@"SimpleCell" bundle:nil] forCellReuseIdentifier:@"SimpleCell"]; 

// These two lines are required for autolayout sizing: 
submissionTable.rowHeight = UITableViewAutomaticDimension; 
submissionTable.estimatedRowHeight = 44; 

这里是对的UITableViewCell的代码(我说这很简单!)

class SimpleCell: UITableViewCell { 
    override func awakeFromNib() { 
     super.awakeFromNib() 
     // Initialization code 
    } 

    override func setSelected(selected: Bool, animated: Bool) { 
     super.setSelected(selected, animated: animated) 
     // Configure the view for the selected state 
    } 

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) { 
     super.init(style: style, reuseIdentifier:reuseIdentifier); 
     self.setTranslatesAutoresizingMaskIntoConstraints(false) 
    } 

    required init(coder aDecoder: NSCoder) { 
     super.init(coder: aDecoder); 
     self.setTranslatesAutoresizingMaskIntoConstraints(false) 
    } 
} 

决赛这里是相当令人沮丧的(和意想不到的)结果: Huge depressing table cell

具有以下不可满足的限制作为两个错误。问题是,这些看起来很简单的满足:

"<NSLayoutConstraint:0x7aef78b0 UITableViewCellContentView:0x7a79fae0.trailingMargin == UILabel:0x7ae36b10'Label label label label l...'.trailing>", 
"<NSLayoutConstraint:0x7aef78e0 UILabel:0x7ae36b10'Label label label label l...'.leading == UITableViewCellContentView:0x7a79fae0.leadingMargin>", 
"<NSLayoutConstraint:0x7a94db00 'UIView-Encapsulated-Layout-Width' H:[UITableViewCellContentView:0x7a79fae0(0)]>" 


"<NSLayoutConstraint:0x7aef6250 UITableViewCellContentView:0x7a79fae0.bottomMargin == UILabel:0x7ae36b10'Label label label label l...'.bottom>", 
"<NSLayoutConstraint:0x7aef6280 UILabel:0x7ae36b10'Label label label label l...'.top == UITableViewCellContentView:0x7a79fae0.topMargin>", 
"<NSLayoutConstraint:0x7a94db30 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x7a79fae0(0.5)]>" 

注意/编辑: 我接受下面的答案,因为1#点。由于某种原因,setTranslatesAutoresizingMaskIntoConstraints(false)实际上是打破了它。

+0

Objective-C或swift? – Loxx

+0

我看到你有两个代码,是视图控制器objc,我猜单元格很快?或者是你的objc在错误上方显示? – Loxx

+0

你使用故事板或xib –

回答

0
  1. 如果您在xib中使用自动布局,那么这些代码是不明智的。

    self.setTranslatesAutoresizingMaskIntoConstraints(false)。

  2. 我已经发现,H:[UITableViewCellContentView:0x7a79fae0(0)]>”,

这意味着你的内容查看的高度为0
可能出错了CellHeight方法
尝试。实现TableViewDelegate返回单元格的高度而不是使用UITableViewAutomaticDimension

+0

我不想实现委托来计算行高度,这是使用UITableViewAutomatic维度完成它的全部要点。看起来我应该为这个视图设置translatesAutoResizingMaskIntoConstraints,因为它是唯一从这个xib加载的,并且没有自动设置(我没有检查)。 – JustinHK

+0

非常奇怪的是,如果在单元格上translatesAutoresizingMaskIntoConstraints是** true **,即使它在内置的UITableViewCell上是错误的,它也可以工作。咦!?所以这条线不仅是没有必要的,而是造成了问题。古怪和好奇。 – JustinHK