[英]UICollectionView cell does not showing
I have defined an UI for my App. 我已经为我的应用程序定义了一个UI。 There is a
UICollectionView
which is 100% defined in Main.StoryBoard
. 在
UICollectionView
中有一个100%定义的Main.StoryBoard
。 I have a fixed number of cells and each cell image has an image in it. 我有固定数量的单元格,每个单元格图像中都有一个图像。 I have setup the number of cell and image for each cell in
Main.StoryBoard
. 我已经在
Main.StoryBoard
设置了每个单元格的数量和图像。 However, when I launched the App, the UICollectionView
is empty. 但是,当我启动该应用程序时,
UICollectionView
为空。 It does not show any cell. 它不显示任何单元格。 What is wrong?
怎么了? Do I have to define a class for this
UICollectionView
? 我是否需要为此
UICollectionView
定义一个类? Do I have to write any ObjectiveC Code? 我必须编写任何ObjectiveC代码吗?
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return 5; // put your array count
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell;
cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"GIVEYOURCELL_IDENTITIFER" forIndexPath:indexPath];// same identifier storyboard cell
UIImageView *thumbail = (UIImageView*) [cell viewWithTag:YOURCELLIMAGETAG]; // give tag here that you put in cell with imageview
thumbail.image = [UIImage imageNamed:@"ImageName"];// give your image here
return cell;
}
Main Point give UICollectionViewDataSource, UICollectionViewDelegate
Delegates in your .h file and also from storyboard to your viewController. UICollectionViewDataSource, UICollectionViewDelegate
在.h文件中以及从情节提要到您的viewController中UICollectionViewDataSource, UICollectionViewDelegate
给UICollectionViewDataSource, UICollectionViewDelegate
委托 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.