Martheli Martheli - 1 year ago 77
iOS Question

Array values not showing up in custom table cell

I am making a simple weather app and my table view is supposed to show the weeks forecast by showing the day on the left side and the high temp on the right side. My cellForRowAtIndexpath is below. It correctly displays the dayarray in my custom daylabel but the maxarray which contains max temperatures doesn't show up. When I print out the max array values it looks correct and all the numbers are listed there but still does not show up. If I just hard code a value in that text label like "Test" then that will show up but the array doesn't.

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! DailyWeatherTableViewCell

cell.daylabel.text = dayarray[indexPath.row] as? String

cell.maxlabel.text = maxarray[indexPath.row] as? String

return cell

UPDATE: My array is set up like this:

dayarray = [dateString1,dateString2, dateString3, dateString4, dateString5, dateString6, dateString7]

maxarray = [max1int, max2int, max3int, max4int, max5int, max6int, max7int]

Its kind of complicated where these values come from but if I print out maxarray, it looks like this:








Answer Source

I think the way you cast the Int to String cause the value to nil. Try change to below instead:

cell.maxlabel.text = String(maxarray[indexPath.row])
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download