I'm trying to update a value for one of my cells. However, the first time that function, cellForItemAtIndexPath
, is called, viewwithtag
returns nil
. The value still changes, though.
/// Llena el contenido de las celdas de la vista
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
var cell = UICollectionViewCell()
switch collectionView.tag
{
// primer condicion para llenar las celdas de productos estrella
case 1:
cell = collectionView.dequeueReusableCellWithReuseIdentifier("cellEstrella", forIndexPath: indexPath) as UICollectionViewCell
if var image = cell.viewWithTag(1) as? UIImageView
{
image.image = WSManagerImages().selectImageAtIndex2("1", inTable: TABLAS.galeriaProductos)
image.clipsToBounds = true
}
return cell
// segunda condicion para llenar las celdas de productos
case 2:
cell = collectionView.dequeueReusableCellWithReuseIdentifier("cellProductoGeneral", forIndexPath: indexPath) as UICollectionViewCell
if var image = cell.viewWithTag(1) as? UIImageView{
image.image = WSManagerImages().selectImageAtIndex("\(indexPath.row+2)", inTable: TABLAS.galeriaProductos)
image.clipsToBounds = true
}
if productosSeleccionados["\(indexPath.section)-"+"\(indexPath.row)"] != nil
{
cell.layer.borderColor = UIColor.blackColor().CGColor
cell.layer.borderWidth = 2.0
cell.layer.cornerRadius = 2.0
}
else
{
cell.layer.borderColor = UIColor.clearColor().CGColor
cell.layer.borderWidth = 0
}
return cell
default:
return cell
}
}