我确定之前已经问过这个问题,但我找不到一个能够解决嵌套if-else和switch-case逻辑问题的答案.
我有UITableView两个部分,每个部分有两个自定义单元格.就是这样.4个细胞.但无论我做什么,我都会得到"在预期返回的功能中失去回归UITableViewCell"
问题如何更改此设置以便在底部获得一个满足快速逻辑的else语句?
任何帮助将非常感谢
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if indexPath.section == 0{
switch (indexPath.row) {
case 0:
let cell0: SettingsCell! = tableView.dequeueReusableCellWithIdentifier("cell0", forIndexPath: indexPath) as! SettingsCell
cell0.backgroundColor = UIColor.redColor()
break
case 1:
let cell1: SettingsCell! = tableView.dequeueReusableCellWithIdentifier("cell1", forIndexPath: indexPath) as! SettingsCell
cell1.backgroundColor = UIColor.whiteColor()
break
default:
break
}
}
if indexPath.section == 1{
switch (indexPath.row) {
case 0:
let cell10: SettingsCell! = tableView.dequeueReusableCellWithIdentifier("cell10", forIndexPath: indexPath) as! SettingsCell
cell10.backgroundColor = …Run Code Online (Sandbox Code Playgroud) 通常当我想设置我的行高然后设置
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 300
}
Run Code Online (Sandbox Code Playgroud)
我estimatedHeightForRowAt应该什么时候使用它有什么好处。
更新!如果我想设置estimatedHeightForRowAt:
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return // what should i put here
}
Run Code Online (Sandbox Code Playgroud)
更新:
如果我按照我的意愿提供estimatedHeightForRowAt,是否有任何效果表视图滚动?. 例如我给出了estimatedHeightForRowAt 500