这是我有这个特殊问题的第二个项目。今天早些时候,我通过故事板创建了一个tableview和原型单元格。我添加了标签编号的子视图,所以我可以从cellforrowatindexpath委托方法中获取它们。尽管当我运行应用程序时,子视图虽然不在正确的位置。我使用autosizing进行布局,并确保设置代表。有没有人有这个问题?原型可重复使用tableview单元格渲染子视图效果不佳
可能相关:有时当我离开故事板并返回时,子视图改变了它们的框架,使它们变平(高度= 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!
}
显示故事板,显示单元的代码,显示如何重用的代码。一切工作正常,你做错了什么 – 2014-10-21 23:15:58
更新...有没有很多特别是w /代码。正如你在截图中看到的,所有的UILabel都是重叠的。事实上,他们中的2个甚至不在该单元格的边界内。它似乎是一个故事板问题,而不是代码问题 – MingMan 2014-10-22 14:37:03