我只是尝试使用自定义UICollectionViewCell调用方法,并且它使用SIGABRT崩溃
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
if([_leaderboardDictionary count] > 0 && indexPath.row == 0)
{
return [self insertLeaderBoardCellAtIndexPath:indexPath];
}
else
{
return [self insertDetailGraphicCellAtIndexPath:indexPath];
}
}
-(CampaignDetailGraphic2Cell *)insertDetailGraphicCellAtIndexPath:(NSIndexPath *)indexPath
{
CampaignDetailGraphic2Cell *cell = (CampaignDetailGraphic2Cell *)[_topCollectionView dequeueReusableCellWithReuseIdentifier:@"detailWebCell" forIndexPath:indexPath];
if(cell == nil)
{
if(is3_5Inches)
{
cell = [[CampaignDetailGraphic2Cell alloc] initWithFrame:CGRectMake(0, 0, 300, 172)];
}
else
if(is4Inches)
{
cell = [[CampaignDetailGraphic2Cell alloc] initWithFrame:CGRectMake(0, 0, 300, 220)];
}
else
if(isIphone6)
{
cell = [[CampaignDetailGraphic2Cell alloc] initWithFrame:CGRectMake(0, 0, 355, 290)];
}
else
if(isIphone6Plus)
{
cell = [[CampaignDetailGraphic2Cell alloc] initWithFrame:CGRectMake(0, 0, 394, 356)];
}
}
[cell setupCell];
...
}
此方法存在于我的CampaignDetailGraphic2Cell类中。
我知道如何调用方法和设置单元格的属性......?
答案 0 :(得分:1)
您不应该使用alloc init创建UICollectionViewCells。您需要在设置集合时注册类或nib文件,然后使单元格出列。完成后,您可以调用单元格上的方法。
即
[self.collectionView registerClass:[CampaignDetailGraphic2Cell class] forCellWithReuseIdentifier:@"CampaignCell"];
然后
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
CampaignDetailGraphic2Cell* cell = (CampaignDetailGraphic2Cell*)[collectionView dequeueReusableCellWithReuseIdentifier:@"CampaignCell" forIndexPath:indexPath];
...
return cell;
}