我想設置我的自定義UICollectionViewCell
屬性:定製UICollectionViewCell不能設置proerty價值
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
// Setup cell identifier
static NSString *cellIdentifier = @"IgCell";
PAInterestGraphCell *cell = (PAInterestGraphCell *)[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
cell.interestCategory = [self.dataArray objectAtIndex:indexPath.row];
// Return the cell
return cell;
}
的PAInterestGraphCell
代碼:
@interface PAInterestGraphCell : UICollectionViewCell
@property (atomic, retain) PAInterestCategory *interestCategory;
@end
#import "PAInterestGraphCell.h"
#import "PAScaleView.h"
@implementation PAInterestGraphCell
@synthesize interestCategory;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
PAScaleView *scaleView = [[PAScaleView alloc] initWithFrame:frame];
scaleView.backgroundColor = [UIColor clearColor];
scaleView.interestCategory = self.interestCategory;
[self.contentView addSubview:scaleView];
}
return self;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
@end
但是,當我訪問了interestCategory
財產它已經失去了所有的價值。
我在這裏錯過了一些明顯的東西嗎?
何時何地爲interestCategory設置了任何值?我發現你在表視圖中這樣做了,但爲什麼你會期望它在init方法中有任何價值? – rdelmar
我將'PAInterestCategory'的8個實例添加到'dataArray'中,並在'cellForItemAtIndexPath'中獲得索引處的一個實例,並將其分配給單元格。 – MartinHN
是的,我明白了,但在你的問題中,你說它在init方法中爲零 - 你爲什麼期望它在那裏有任何價值?那時你還沒有設置它。 – rdelmar