[英]Converting Objective to Swift Table view not displaying the data in the cells
I'm still very inexperienced with Swift and am having a problem converting an objective-c based app. 我对Swift还是很缺乏经验,在转换基于Objective-C的应用程序时遇到了问题。 Most of the app is working ... including changing size and colors of section headers and background color of the cells but I cannot display the content of the cells (a TextView and a switch).
大多数应用程序都在工作...包括更改节标题的大小和颜色以及单元格的背景颜色,但我无法显示单元格的内容(TextView和开关)。 Any suggestions about fixing this would be appreciated.
任何解决此问题的建议,将不胜感激。 I'm including the code where I change the background color which is where I suspect the problem resides:
我将代码包含在更改背景颜色的位置,这是我怀疑问题所在的位置:
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.