uicollectionviewcontroller iphone ios uicollectionview

iphone - uicollectionviewcontroller - Error de afirmación de iOS en UICollectionView



uicollectionviewcell swift (7)

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 que ocurre en la salida.

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

¿Alguien puede arrojar luz sobre esto?


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];

ese TAMBIÉN en el archivo de punta, cuando selecciona la vista reutilizable de la colección de nivel superior, utiliza el inspector de atributos y se asegura de que el Identifier esté configurado en el mismo valor que le está pasando al parámetro withReuseIdentifier: .


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

No tenía una subclase personalizada de un diseño de flujo, pero establecía el headerReferenceSize en el existente directamente. Así que en Interface Builder con el 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 configuro el tamaño en el código.


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

De todos modos, el collectionView que estoy usando está dentro de un archivo xib separado (no un guión gráfico) y de la documentación ...

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

Gracias


He visto este error emergente cuando uso múltiples UICollectionViews con ReuseIdentifiers únicos. En ViewDidLoad desea registrar cada identificador reuse de 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" desea asegurarse de que no intenta establecer una celda para collectionView1 para el reuseIdentifier para collectionView2 o usted obtendrá este error.

NO HAGA 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;

Haz 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;


Necesitas registrarte como abajo:

[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"MY_CELL"];


Reemplazar

NSString *CellIdentifier = @"Cell";

con

static NSString *CellIdentifier = @"Cell";


Yo tuve el mismo problema. Así es como lo resolví.

Movimiento

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

estar en - (void)viewDidLoad ,

en lugar de método - (void)awakeFromNib .