[Solved] Showing array content on a button, using a label


So just to get this straight. Each time you press the button you want to display the next element in the array through the label. Okay, that should be fairly simple. Something like below will do that for you.

var primeString = ["60","52","81","61","85"]
var currentElement = 0

@IBOutlet var PrimeLabel: UILabel!

@IBAction func NewAction(sender: AnyObject) {
   if currentElement < primeString.count {
      PrimeLabel.text = primeString[currentElement]
      currentElement++
   } else {
      print("No more elements to display.")
   }
}

No need to have the view did load, as we don’t need to do any setup once the view has loaded. I hope this helps you out.

0

solved Showing array content on a button, using a label