繁体   English   中英

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

[英]Converting Objective to Swift Table view not displaying the data in the cells

我对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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM