2014-10-31 96 views
0

我只是試圖調用方法與自定義UICollectionViewCell和它與SIGABRTUICollectionViewCell問題調用方法

-(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

你在哪裏使這個小區?代碼,故事板,xib? – rdelmar 2014-10-31 20:31:26

回答

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; 
} 
+0

嗨,感謝您的回覆。我繼續前進並刪除了alloc調用...單元現在擴展到集合視圖的大小。但是現在,我在控制器的哪個位置設置了單元格的屬性(例如標題文本,背景顏色等)......?謝謝! – 2014-10-31 19:56:35

+0

您可以在' - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath'中設置屬性。 – 2014-10-31 20:18:16

+0

偉大的我現在可以...但實際問題(不允許我設置屬性)是.xib文件沒有正確的類集... *嘆息* ...它被設置爲UITableViewCell。 .. 謝謝你的幫助!!! – 2014-10-31 21:00:25