如何在swift 3中为UITable视图提供单元格缩进级别?

时间:2017-08-24 06:57:32

标签: ios uitableview swift3

我正在从模型类获取Web服务数据,以及如何使用缩进级别将数据发送到表视图单元而不使用外部库,并且需要显示如下图所示

enter image description here

1 个答案:

答案 0 :(得分:0)

我认为三种细胞的手段不会让你困惑

所以这是第二种方法

class TableViewCell: UITableViewCell {
    @IBOutlet var theLabel: UILabel!
    @IBOutlet var leftConstraint: NSLayoutConstraint!
}

在某些VC中,我认为这是最简单的方法

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "testCell", for: indexPath) as! TableViewCell
    // let arr = [1, 2, 2, 3, 3, 2, 1, 1, 2, 3]
    let order = self.arr[indexPath.row]
    switch order {
    case 1: cell.leftConstraint.constant = 10
    case 2: cell.leftConstraint.constant = 30
    case 3: cell.leftConstraint.constant = 50
    default: break
    }

    cell.theLabel.text = "I'm level\(order)"
    return cell
}

enter image description here