Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Return items in an array one by one until all items have been returned then start again

Hi,


What have is a UITable with a customCellwhich contains mutiple labes and what I want to do is be able to paint those labels with one of the four colors in an array. In other words I would like to paint the first row (cell) red, the second, blue, the third green, the fourth yellow and then start over again with the fifth one being red and so on.


The code I have blow keeps returning the first color only (red). Any idea how can I acoplish what I'm describing above?




  1. class CustomCell: UITableViewCell {

  2. @IBOutlet weak var labelPrice: UILabel!
  3. @IBOutlet weak var labelDiscount: UILabel!
  4. @IBOutlet weak var labelSavings: UILabel!
  5. @IBOutlet weak var labelTaxes: UILabel!
  6. let myColors = [colorMyRed, colorMyBlue, colorMyGreen, colorMyYellow]

  7. var nextItemIndex = 0// why this doesnt hold the value after being modified
  8. func myColor() -> UIColor {
  9. let result = myColors[nextItemIndex]
  10. nextItemIndex = nextItemIndex + 1
  11. return result
  12. }
  13. override func awakeFromNib() {
  14. super.awakeFromNib()

  15. let color:UIColor = myColor()

  16. labelPrice.textColor = color
  17. labelDiscount.textColor = color
  18. labelSavings.textColor = color
  19. labelTaxes.textColor = color
  20. }
  21. }

Posted on Feb 6, 2016 11:11 AM

Reply

There are no replies.

Return items in an array one by one until all items have been returned then start again

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.