ios - UICollectionViewCell subclass init never run -
i have added collection view in viewdidload this...
self.collectionview = [[uicollectionview alloc] initwithframe:cgrectmake(0, 0, 10, 10) collectionviewlayout:flowlayout]; self.collectionview.delegate = self; self.collectionview.datasource = self; self.collectionview.backgroundcolor = [uicolor whitecolor]; [self.collectionview registerclass:[cameracell class] forcellwithreuseidentifier:cameracellreuseidentifier]; [self.collectionview settranslatesautoresizingmaskintoconstraints:no]; [self.view addsubview:self.collectionview];
and have uicollectionviewcell subclass called cameracell init this...
- (id)init { self = [super init]; if (self) { // add customisation here... [[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(imagechanged:) name:@"image" object:nil]; self.contentview.backgroundcolor = [uicolor yellowcolor]; self.imageview = [[uiimageview alloc] initwithframe:cgrectzero]; self.imageview.contentmode = uiviewcontentmodescaleaspectfill; self.imageview.clipstobounds = yes; [self.imageview settranslatesautoresizingmaskintoconstraints:no]; [self.contentview addsubview:self.imageview]; nsdictionary *views = nsdictionaryofvariablebindings(_imageview); [self.contentview addconstraints:[nslayoutconstraint constraintswithvisualformat:@"v:|[_imageview]|" options:0 metrics:nil views:views]]; [self.contentview addconstraints:[nslayoutconstraint constraintswithvisualformat:@"|[_imageview]|" options:0 metrics:nil views:views]]; } return self; }
but when run app collection view there , can scroll can't see cells. have added breakpoint in cell's init , never gets called. there method have override?
edit
when log cell in cellforitematindexpath...
- (uicollectionviewcell *)collectionview:(uicollectionview *)collectionview cellforitematindexpath:(nsindexpath *)indexpath { cameracell *cell = [collectionview dequeuereusablecellwithreuseidentifier:cameracellreuseidentifier forindexpath:indexpath]; nslog(@"%@", cell); return cell; }
it displays correct class...
<cameracell: 0x1f07ba30; baseclass = uicollectionviewcell; frame = (0 20; 320 280); layer = <calayer: 0x1f07bb40>>
the method need implement - (instancetype)initwithframe:(cgrect)rect
Comments
Post a Comment