2014-05-13 62 views
-2

我有這個UICollectionView,我創建progrematically。 現在,我想添加一個服裝單元格,它是我創建的單元格類。添加服裝細胞progrematically

所以電池類稱爲GridCell.h/GridCell.m,我現在需要把它添加到我的CollectionView:

UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc] init]; 
    self.GridView=[[UICollectionView alloc] initWithFrame:self.view.frame collectionViewLayout:layout]; 
    GridCell *cell=[[GridCell alloc] init]; //my cell 

    [ self.GridView registerClass:cell forCellWithReuseIdentifier:@"Cell"]; //not good ! 
    [self.GridView setDelegate:self]; 
    [self.GridView setDataSource:self]; 
    [self.view addSubview:self.GridView]; 
+1

什麼是你的問題?什麼不起作用和/或與實際結果有關的預期結果是什麼? – Pfitz

+0

@Pfitz如果你知道這個話題,你會以某種方式看待我的錯誤,而不是做出一個愚蠢的假設,請參閱Martin的答案,並從中學習。 – Curnelious

+1

Curnelious:你不會在這樣的評論上結交很多朋友! - 我碰巧看到了這個問題,但這並不能改變這個事實,即清楚地描述問題的責任是*(例如:它不會編譯爲以下錯誤信息),而且「不好!」不是一個明確的描述。 @菲菲沒有做出任何「愚蠢的假設」。他要求澄清,這可能是解決問題的第一步。 –

回答

2

您必須先註冊細胞的,而不是類的一個實例:

[self.GridView registerClass:[GridCell class] forCellWithReuseIdentifier:@"Cell"]; 
+0

非常感謝它的工作。 – Curnelious