当前位置: 动力学知识库 > 问答 > 编程问答 >

ios - How to get integer from superview in Xcode?

问题描述:

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:

分享给朋友:
您可能感兴趣的文章:
随机阅读: