ios - How to get index number from within tableView: cellForRowAtIndexPath: using `indexPath` argument? -


i want change backgroundcolor of uitableviewcell , want index number of each table view cell, because want change color of cells respect index number.

however how can index number within tableview: cellforrowatindexpath:? example, in following code (within tableview: cellforrowatindexpath:):

let numberofcell = indexpath.length // returns 2, if add more cells println(indexpath) // returns <nsindexpath: 0xc000000000000016> {length = 2, path = 0 - 0} in 0..<numberofcell {     let alpha = cgfloat(1.0 - double(i) / 10.0)     cell.backgroundcolor = uicolor(red: 227/256, green: 245/256, blue: 61/256, alpha: alpha) }  return cell 

i want change alpha value of each cell respect index number, code above makes cell's alpha 1.0, because numberofcell 2, though table view has 4 objects. i'm not sure why returns 2. added more cells result didn't change.

so why return 2 , how can correct value of each index? want 0 first cell, 1 second, 2 third, , goes on.

i tried access path property of index path shown on output of println(indexpath) above, reasons nsindexpath doesn't have such properties...

try indexpath.row or, if using sections too, try indexpath.section in addition. :)


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -