简体   繁体   English

UICollectionView单元格未显示

[英]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, UICollectionViewDelegateUICollectionViewDataSource, UICollectionViewDelegate 委托

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 UICollectionView单元内部加载,但未显示UICollectionView - UICollectionView Cell Internally loaded but UICollectionView is not Showing UICollectionView Vertical显示最后一半的单元格 - UICollectionView Vertical showing half the cell in the end UICollectionView显示与所选单元格相关的图像 - UICollectionView showing images related to the selected cell UICollectionView的单元格选择无法快速运行 - cell selection of UICollectionView does not work in swift UICollectionView仅显示一个单元格 - 在滚动视图时会更改 - UICollectionView showing only one cell - which changes when the view is scrolled 单击UICollectionview单元格后直到滚动,图像未显示在UIImageview上 - Image not showing on my UIImageview after clicking on UICollectionview cell until scroll UICollectionView 接收到的单元格的布局属性,其索引路径不存在 - UICollectionView received layout attributes for a cell with an index path that does not exist UICollectionView:ScrollToItem到中心单元格不适用于水平集合视图 - UICollectionView: ScrollToItem to center cell does not work on horizontal collection view 为什么单击单元格时UICollectionView会向上滚动? - Why does my UICollectionView scroll up when clicking on a cell? UICollectionView收到了一个索引路径不存在的单元格的布局属性 - UICollectionView recieved layout attributes for a cell with an index path that does not exist
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM