tldr; Auto constrains appear to break on push segue and return to view for custom cells
Edit:我提供了一个github示例项目,展示了发生的错误
应用程序的标题依赖于应用程序的标题,我需要为应用程序创建不同的标题行长度.单元格正确加载到视图中,但如果我按单元格将帖子按推式顺序加载到包含WKWebView的视图中,您可以看到,如屏幕截图所示,单元格会立即移动到错误的位置.当通过UINavigationController的"后退"按钮加载视图时,也可以查看该视图.
在这个特殊的例子中,我按下了最后一个单元格,标题是"我在巴黎拍的两个朋友",所有内容都正确加载.然后,如下一个屏幕截图所示,在加载第二个视图的背景中,由于未知原因,这些单元格都向上移动.然后,当我加载回视图时,你可以看到屏幕稍微向上移动,我实际上无法滚动到显示的任何下方.这似乎是随机的,就像其他测试一样,当视图加载回来时,底部单元格下的空白不会消失.
我还附上了一张图片,其中包含了单元格所具有的约束条件.
图片(我需要更多的声誉来提供这个问题的图片,显然,他们在这个imgur相册中):http://imgur.com/a/gY87E
我的代码:
方法,以允许单元格在旋转时正确调整视图的大小:
override func layoutSubviews() {
super.layoutSubviews()
self.contentView.layoutIfNeeded()
// Update the label constaints
self.titleLabel.preferredMaxLayoutWidth = self.titleLabel.frame.width
self.detailsLabel.preferredMaxLayoutWidth = self.detailsLabel.frame.width
}
tableview中的代码
override func viewDidLoad() {
super.viewDidLoad()
// Create and register the custom cell
self.tableView.estimatedRowHeight = 56
self.tableView.rowHeight = UITableViewAutomaticDimension
}
创建单元格的代码
override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
if let cell = tableView.dequeueReusableCellWithIdentifier("LinkCell", forIndexPath: indexPath) as? LinkTableViewCell {
// Retrieve the post and set details
let link: Link = self.linksArray.objectAtIndex(indexPath.row) as Link
cell.titleLabel.text = link.title
cell.scoreLabel.text = "\(link.score)"
cell.detailsLabel.text = link.stringCreatedTimeIntervalSinceNow() + " ago by " + link.author + " to /r/" + link.subreddit
return cell
}
return nil
}
If you require any more code or information please ask and I shall provide what is necessary
谢谢你的帮助!