问题描述:

I try to get a integer from a viewcontroller and pass to a subclass cell.m. Here is the code:

the superview controller h.

@property (nonatomic, assign) NSInteger cellnumberinrow;

the superview controller m.

self.cellnumberinrow = 5; (it may change later)

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

static NSString *identifier = @"wordscollectioncell";

CVcell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];

CVcell.h

@property (nonatomic, assign) NSInteger cellnumberinrow;

CVcell.m

self.cellnumberinrow= [(superview Controller *)[self superview] cellnumberinrow];

No error return but get crash on runtime. Why? Any help is appreciated.

网友答案:

Instead of

self.cellnumberinrow = [(superview Controller *)[self superview] cellnumberinrow]; in CVcell.m

Please, consider use

cell.cellnumberinrow = self.cellnumberinrow; in the method collectionView:cellForItemAtIndexPath:

相关阅读:
Top