gpt4 book ai didi

static - 如何设置静态表中单元格的背景颜色 swift Xcode 6

转载 作者:行者123 更新时间:2023-12-02 03:09:30 24 4
gpt4 key购买 nike

我有静态表,我为 tableview -> tableView.backgroundColor = UIColor.redColor() 设置背景颜色,当我在静态表中有 3 行时,tableview 是彩色的,3 行是白色的,如何修复该单元格的背景颜色?此代码不适用于静态 表->

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! UITableViewCell


cell.textLabel!.text = numbers[indexPath.row]
cell.backgroundColor = UIColor.greenColor()

return cell
}

最佳答案

在静态 TableView 中,您不必实现 cellForRowAtIndexPath。所以我建议你实现以下代码:

override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
// Change the color of all cells
cell.backgroundColor = UIColor.greenColor()
}

关于static - 如何设置静态表中单元格的背景颜色 swift Xcode 6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29569246/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com