我試圖實現的是一個3x3表格,其中包含UICollectionView
。但是它在運行應用程序時不會顯示任何單元格。它確實顯示了CollectionView
的背景顏色(我設置爲藍色)有人可以幫我嗎?UICollectionView - 不顯示單元格
我所做的是創建一個storyboard
,並簡單地將CollectionViewController
拖到它上面。這個控制器也帶了一個嵌套的CollectionView
。然後,我簡單地使用設置來使其背景變成藍色,並添加一個單元格,使其背景變爲紫色(兩者都僅用於測試)。最後將一個UILabel
拖到它上面。現在運行時只顯示藍色背景,但沒有單元格,即使它們在編輯器中清晰可見。然後,我嘗試創建一個自定義UICollectionViewController
,將類指定給CollectionViewController
而不是標準類,並對單元執行相同操作(指定自定義UICollectionViewCell
)。在自定義UICollectionViewController
我實現下面的方法:
-(NSIntegear)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return 9;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"Cell";
AboutYourGoalsMultiSelectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
[[cell goal]setText:@"T"];
return cell;
}
我所述小區設置到「小區」的標識符和由數據源和代表的的CollectionView和定製UICollectionViewController之間的出口連接。一切都很好。 那麼我錯過了什麼?在簡單地使用編輯器進行所有這些調整之前,它不應該顯示某種方式嗎?
是用於CollectionViewCell小區標識符設置爲 「小區」? – mharper
是的,集合可重用視圖>標識符被設置爲「單元格」和標識>恢復ID以及 –
沒有什麼突然出現在我身上。我會在'collectionView:cellForItemAtIndexPath:'中設置一個斷點,以確保它被調用,並且b)看看還有什麼可能會出錯的。 – mharper