0

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
    }
}
royhowie
  • 11,075
  • 14
  • 50
  • 67
  • Not enough information here to answer your question. For example, we have no idea where you are even setting the `tag` property on your collection view. All I can tell you is that your collection view is being loaded with all of its cells before your code is being run that sets the `tag` property. Until you give us more code, that's all I can say. – Mark S Nov 10 '14 at 21:37
  • Is this a custom collectionviewcell? – Mark McCorkle Nov 10 '14 at 21:44
  • i set the tag in my storyboard, i solved this closing my project and opening again ... i feel like Xcode have a lot of bugs in the last update – Emmanuel T Nov 19 '14 at 16:36

0 Answers0