任何人都可以看到为什么我不能将我的tableView单元格的背景颜色属性设置为我在ViewDidLoad()
中创建的数组的颜色?我的viewDidAppear()
方法中也有一个self.tableView.reloadData()
。让我知道。为什么我无法从颜色数组中随机设置颜色到tableViewCells?
override func viewDidLoad() {
super.viewDidLoad()
colorArray += [UIColor.whiteColor(), UIColor.blackColor(), UIColor.greenColor(), UIColor.yellowColor(), UIColor.redColor(), UIColor.purpleColor(), UIColor.orangeColor(), UIColor.blueColor(), UIColor.brownColor(), UIColor.darkGrayColor(), UIColor.lightGrayColor(), UIColor.grayColor(), UIColor.cyanColor(), UIColor.magentaColor(), UIColor.clearColor()]
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)
for color in colorArray {
cell.backgroundColor = color
}
return cell
}
哪里是在你的代码的随机部分? – Wain
http://stackoverflow.com/questions/29779128/how-to-make-a-random-background-color-with-swift也许这对你有帮助 – Patrick
@jamie Baker看到我的答案 –