【发布时间】:2016-03-10 19:32:13
【问题描述】:
我有表格视图来显示用户的 cmets
我需要根据内容高度使每一行的高度动态化
我搜索了一下,找到了
heightForRowAtIndexPath 方法
但它不工作或者我不知道如何使用它!
这是我的代码:
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath)
let username = cell.viewWithTag(1) as! UILabel
let comment = cell.viewWithTag(2) as! UITextView
username.text = usernames[indexPath.row]
comment.text = comments[indexPath.row]
return cell
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.comments.count
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension;
}
【问题讨论】:
标签: ios swift uitableview