将Objective转换为Swift Table视图不显示单元格中的数据

时间:2015-07-25 19:25:33

标签: ios swift uitableview xcode6

我仍然对Swift缺乏经验,并且在转换基于Objective-c的应用程序时出现问题。 大多数应用程序正在工作......包括更改节标题的大小和颜色以及单元格的背景颜色,但我无法显示单元格的内容(TextView和开关)。 任何有关解决此问题的建议将不胜感激。 我包含了我改变背景颜色的代码,这是我怀疑问题所在的地方:

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

    //variable type is inferred
    var index = indexPath.row

    NSLog ("index %d",indexPath)

    var cell = tableView.dequeueReusableCellWithIdentifier("CELL") as? UITableViewCell

    if cell == nil {
        cell = UITableViewCell(style: UITableViewCellStyle.Value1, reuseIdentifier: "CELL")
    }

    //we know that cell is not empty now so we use ! to force unwrapping
    var grayishCyan = colorWithHexString("#9bc2c2")
    var grayishRed = colorWithHexString("#ffc2c2")

    if (indexPath.row == 0 || indexPath.row%2 == 0) {
        cell!.backgroundColor = grayishCyan;
    }
    else {
        cell!.backgroundColor = grayishRed
    }

    return cell!
} // end of cellForRowAtIndexPath

1 个答案:

答案 0 :(得分:-1)

我删除了cellForRowAtIndexPath函数并将其替换为willDisplayCell函数

相关问题