On tableView's cells, I'm trying to define a gradient with the following Swift code:
func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
var cell:UITableViewCell = self.tableView?.dequeueReusableCellWithIdentifier("cell") as UITableViewCell
cell.backgroundColor=UIColor.clearColor()
let gradient : CAGradientLayer = CAGradientLayer()
var arrayColors:Array<AnyObject> = [UIColor.blackColor().CGColor, UIColor.whiteColor().CGColor]
gradient.colors=arrayColors
gradient.frame = cell.bounds
cell.layer.insertSublayer(gradient, atIndex: UInt32(indexPath.row))
return cell
}
The behavior is very chaotic: when the view is first loaded, all cells have a white background. And if I scroll up and down, some content's cells disappear (title and subtitle) and the gradient finally appears in these cells (randomly, some other cells stay with a white background). Is it related to this cast -> UInt32(indexPath.row) ?