I am taking time values stored in seconds in an Int array and attempting to put it on a UILabel which are then counting down trigged by a countDown function. I'm unable to get the time to count down in each cell, nor am I able to print the array without getting only the raw seconds value without formatting it as you'll see below. For now I can only display the raw value on a UILabel per cell as: 6532
(the hours, minutes, seconds)
I can't format the array either when trying to print it alone in the for loop
as you'll see below. The array is stored as an Int.
When using a for loop in the countDown function, I can print to the logs the time formatted: HH:MM:SS
. But not otherwise.
Here's my countDown function:
func countDown() {
//timerInt is an array where I'm storing the Int values.
for i in 0 ..< timerInt.count {
let hours = timerInt[i] / 3600
let minsec = timerInt[i] % 3600
let minutes = minsec / 60
let seconds = minsec % 60
print(String(format: "%02d:%02d:%02d", hours, minutes, seconds))
timerInt[i]--
print(self.timerInt[i])
}
}
I'm trying to do this in a cellForRowAtIndexPath method. The UILabel is located in a separate class:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let myCell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! cell
//This is the first item i'm posting on a UILabel and it works fine.
myCell.productName.text = productName[indexPath.row]
/*This cell/label I'm unable to format like in the for loop
which is formatted as a string*/
myCell.secondLabel.text = ("\(intArray[indePath.row])")
/*how do I format the intArray here so that the time
appears HH:MM:SS?? */
return myCell
}
How can I format the intArray
so that it prints to the logs and to the UI as a formatted time (HH:MM:SS) like in the for loop
when i print to the logs with the String formatter?
Any help is much appreciated!