Error de aserción de iOS en UICollectionView


Estoy recibiendo el error ...

*** Assertion failure in -[UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:], /SourceCache/UIKit/UIKit-2372/UICollectionView.m:2249

Al intentar mostrar un UICollectionView.

Las líneas que lo causan son...

static NSString *CellIdentifier = @"Cell";

UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];

Error en el dequeue.

No hay otros errores, así que estoy luchando para saber por dónde empezar con esto.

¿Puede alguien arrojar luz sobre esto?

Author: Fogmeister, 2012-09-26

7 answers

Necesitas registrarte como abajo:

[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"MY_CELL"];
 36
Author: Gaurav,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-11-10 10:53:43

Estado leyendo los documentos (posiblemente debería haber hecho esto primero:))

De todos modos, la collectionView que estoy usando está dentro de un archivo xib separado (no un storyboard) y de los documentos...

Important: You must register a class or nib file using the
registerClass:forCellWithReuseIdentifier: or
registerNib:forCellWithReuseIdentifier: method before calling this method.

Gracias

 28
Author: Fogmeister,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-09-26 10:48:34

Asegúrese de que si utiliza el método registerNib::

UINib *nibH = [UINib nibWithNibName:HEADER_ID bundle:nil];
[collectionView registerNib:nibH
 forSupplementaryViewOfKind:UICollectionElementKindSectionHeader 
        withReuseIdentifier:HEADER_ID];

Que TAMBIÉN en el archivo nib, cuando seleccione la vista reutilizable de la colección de nivel superior, use el inspector de atributos y asegúrese de que el Identifier esté establecido en el mismo valor que está pasando al parámetro withReuseIdentifier:.

 3
Author: bshirley,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-02-05 15:58:36

Yo tenía el mismo problema. Así es como lo resolví.

Mover

[self.pictureCollectionView registerNib:[UINib nibWithNibName: bundle:nil] forCellWithReuseIdentifier:reuseID]

Estar en - (void)viewDidLoad,

En lugar del método - (void)awakeFromNib.

 1
Author: U.Jhon,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-06-05 11:22:53

Sustitúyase

NSString *CellIdentifier = @"Cell";

Con

static NSString *CellIdentifier = @"Cell";
 0
Author: CAMOBAP,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-09-26 10:41:03

He visto este error emergente al usar múltiples UICollectionViews con ReuseIdentifiers únicos. En viewDidLoad desea registrar el reuseIdentifier de cada collectionView de la siguiente manera:

[_collectionView1 registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"collectionView1CellIdentifier"];
[_collectionView2 registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"collectionView2CellIdentifier"];

Luego, cuando llegue a "- (UICollectionViewCell *)collectionView: (UICollectionView *)collectionView cellForItemAtIndexPath: (NSIndexPath*) indexPath", debe asegurarse de que no intente establecer una celda para collectionView1 en el reuseIdentifier para collectionView2 o obtendrá esto error.

NO HAGAS ESTO: (O collectionView2 verá el Identificador incorrecto y lanzará un ajuste antes de ver el identificador que esperaba)

UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collectionView1CellIdentifier" forIndexPath:indexPath];

if(collectionView != _collectionView1){
   cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collectionView2CellIdentifier" forIndexPath:indexPath];
}

cell.backgroundColor = [UIColor greenColor];
return cell;

HAGA ESTO :

UICollectionViewCell *cell;

if(collectionView == _collectionView1){
    cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collectionView1CellIdentifier" forIndexPath:indexPath];
}else{
   cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collectionView2CellIdentifier" forIndexPath:indexPath];
}

cell.backgroundColor = [UIColor greenColor];
return cell;
 0
Author: ColossalChris,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-04-15 13:20:31

Tengo este bloqueo en iOS 9 solo (iOS 10/11 están funcionando bien).

No tenía ninguna subclase personalizada de un Diseño de Flujo, pero estableciendo el headerReferenceSize en el existente directamente. Así que en Interface Builder con Encabezado de sección habilitado obtuve este bloqueo, sin la marca de verificación todo funciona bien y los encabezados se muestran correctamente, ya que establecí el tamaño en el código.

introduzca la descripción de la imagen aquí

 0
Author: fl034,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-09-12 15:40:29