【发布时间】:2016-08-16 12:50:07
【问题描述】:
我正在为列表创建一个视图。它在字幕中具有动态长度。所以我使用了 UITableViewAutomaticDimension 属性。我没有应用任何约束,因为两个标签都是表格视图单元格属性,所以不需要创建新的自定义单元格。
但是在运行这个项目之后,我标记了 UITableViewAutomaticDimension 不能正常工作。我不知道我做错了什么。我的代码如下所示
视图确实加载了
@IBOutlet weak var tblabc: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
tblabc.separatorColor = UIColor.clearColor()
tblabc.estimatedRowHeight = 44
tblabc.rowHeight = UITableViewAutomaticDimension
// Do any additional setup after loading the view.
}
表视图委托和数据源
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 5
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
var cell = tableView.dequeueReusableCellWithIdentifier("Cell")
if (cell == nil)
{
cell = UITableViewCell(style: .Subtitle, reuseIdentifier: "Cell")
cell?.selectionStyle = .None
cell?.detailTextLabel?.font = _SETREGULARFONT_KARLA(IS_IPAD ? 19:15)
cell?.textLabel?.font = _SETBOLDFONT_KARLA(IS_IPAD ? 17:13)
cell?.detailTextLabel?.textColor = getColorFromRGB(120, G: 132, B: 158, A: 1.0)
cell?.detailTextLabel?.numberOfLines = 0
cell?.detailTextLabel?.lineBreakMode = .ByTruncatingTail
cell?.selectionStyle = .None
}
cell?.textLabel?.text = "Testing" + "\(indexPath.row)"
cell?.detailTextLabel?.text = "tesfhjdsfskdfhjkfhdjskfhsjkdfhdjsxdfgfjljkgjfklgfhsdjfhjkdshfdjskfhdjfjkfhafyhdsifjhdjksfbshdjkfkhdksjfhdjsfyhds8ufdhsfjkhdsfjhdfudsiufhdsfh"
cell?.imageView?.image = UIImage(named: "new_temp")
return cell!
}
查看如下图所示
【问题讨论】:
标签: ios swift uitableview