我已經創建了一個UIcollectionView和一個包含一些字符串@ [@「Item One」,「Item Two」,@「Item Three」]的數組;在uicollectionviewcell中設置文本
在泰伯維我這樣做:
NSString *object = self.titlesArray[indexPath.row];
cell.textLabel.text = object;
但我真的不知道如何在UIcollectionView項目做到這一點。
我已經創建了一個UIcollectionView和一個包含一些字符串@ [@「Item One」,「Item Two」,@「Item Three」]的數組;在uicollectionviewcell中設置文本
在泰伯維我這樣做:
NSString *object = self.titlesArray[indexPath.row];
cell.textLabel.text = object;
但我真的不知道如何在UIcollectionView項目做到這一點。
UICollectionViewCell
沒有默認的單元格樣式。 你必須創建一個自定義UICollectionViewCell
並在裏面添加一個UILabel
。
UICollectionViewCell
沒有默認textLabel
作爲UITableviewCell
有,您必須根據您的需要創建自定義UICollectionViewCell
。
你可以看看this教程如何創建自定義集合視圖單元格。
像已發佈的其他人一樣,有UILabel
類型的財產。如果您不瞭解課程,請按CMD,然後選擇您所從事的課程。在UICollectionView
,你會看到的情況下,有UICollectionViewCell
類Foundation
內沒有定義屬性(:
NS_CLASS_AVAILABLE_IOS(6_0) @interface UICollectionViewCell : UICollectionReusableView
@property (nonatomic, readonly) UIView *contentView; // add custom subviews to the cell's contentView
// Cells become highlighted when the user touches them.
// The selected state is toggled when the user lifts up from a highlighted cell.
// Override these methods to provide custom UI for a selected or highlighted state.
// The collection view may call the setters inside an animation block.
@property (nonatomic, getter=isSelected) BOOL selected;
@property (nonatomic, getter=isHighlighted) BOOL highlighted;
// The background view is a subview behind all other views.
// If selectedBackgroundView is different than backgroundView, it will be placed above the background view and animated in on selection.
@property (nonatomic, retain) UIView *backgroundView;
@property (nonatomic, retain) UIView *selectedBackgroundView;
@end
我有同樣的問題,所以我做了一個小型的教程要做到這一點:How to make a simple collection view with Swift的代碼是斯威夫特但是這個過程是有關目的C.同一
的主要步驟是
UICollectionViewCell
的自定義子類以保存單元格標籤出口。UICollectionViewDataSource
和UICollectionViewDelegate
及其方法。
一個好地方開始:http://www.raywenderlich.com/22324/beginning-uicollectionview-in-ios-6-part-12。谷歌也很有幫助 – fguchelaar 2014-11-21 10:51:48