【问题标题】:What should I write in tableView(_:cellForRowAtIndexPath:) method to custom cells?我应该在 tableView(_:cellForRowAtIndexPath:) 方法中为自定义单元格写什么?
【发布时间】:2016-02-28 14:08:24
【问题描述】:

我正在设计一个包含 3 个自定义单元格的表格视图。 我想通过添加独特的配件类型来定制它们。 我用静态单元格创建了一个 tableViewController。每个单元格我都写了一个特殊的标识符和特殊的类。

对于 3 个自定义单元格,我的 tableView 基金应该是什么样子?

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let CityCellIdentifier = "CityTableViewCell"

    let cell = tableView.dequeueReusableCellWithIdentifier(CityCellIdentifier, forIndexPath: indexPath) as! CityTableViewCell
    // Configure the cell...

    return cell
}

我应该为此创建三个单元格变量吗?

【问题讨论】:

标签: ios swift uitableview


【解决方案1】:

根据我的回答 here,请使用您自己的以下代码变体:

override func tableView(tableView: UITableView?, cellForRowAtIndexPath indexPath: NSIndexPath?) -> UITableViewCell? {

    if (criteria for cell 1) {
        let cell = tableView!.dequeueReusableCellWithIdentifier("cell1", forIndexPath: indexPath) as? cell1
        return (cell)
    }
    else {
        let cell = tableView!.dequeueReusableCellWithIdentifier("cell2", forIndexPath: indexPath) as? cell2
        return (cell)
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-07
    • 2015-04-20
    • 1970-01-01
    • 2012-06-06
    相关资源
    最近更新 更多