gpb*_*pbl 6 uitableview uikit ios ios8
我正在创建2个部分UITableView.第一部分使用UITableViewCells与Default风格,第二个使用Subtitle风格.两个单元格都可以具有多行文本标签.
我把桌子设置rowHeight为UITableViewAutomaticDimension.
正如您从下面的屏幕截图中看到的那样,UITableViewAutomaticDimension在使用Subtitle样式时仅部分尊重:高度似乎适合textLabel高度但不适合高度detailLabel.
如何让Subtitle细胞达到合适的高度?
一些代码:
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.estimatedRowHeight = 80
tableView.rowHeight = UITableViewAutomaticDimension
tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "defaultCell")
tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "subtitleCell")
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if indexPath.section === 1 {
var cell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "subtitleCell")
cell.textLabel?.numberOfLines = 0
cell.textLabel?.text = "A Long text..."
cell.detailTextLabel?.numberOfLines = 0
cell.detailTextLabel?.text = "A Long text..."
return cell
}
else {
var cell = tableView.dequeueReusableCellWithIdentifier("defaultCell") as! UITableViewCell
cell.textLabel!.text = "A long text..."
cell.textLabel?.numberOfLines = 0
return cell
}
}
Run Code Online (Sandbox Code Playgroud)
我试图实现一个子类,UITableViewCell但是我遇到了autolayout和section titles(很长的故事)的许多问题,所以我想知道我是否能以更简单的方式解决问题.
| 归档时间: |
|
| 查看次数: |
397 次 |
| 最近记录: |