[英]Loading each cell with different data Collection View in IOS
我是iOS应用程序开发的新手。我陷入一个问题。我有一个集合视图。我想用不同的小部件加载该集合视图的每个单元格,即在第一个单元格中有一个表格视图,每个单元格都有图像,第二个单元格应该是带有imageview的另一个表格视图,2个标签等3单元格应该具有另一个设计。我可以这样做吗?
Although you can do that, it sort of defeats the purpose of the collection view as a collectionview should be a set of similar views. 尽管您可以这样做,但是它违反了集合视图的目的,因为集合视图应该是一组类似的视图。
But it can be done if you implement cellForItemAtIndexPath and use a case statement for laying out the subviews depending on the item 但是,如果实现cellForItemAtIndexPath并使用case语句根据项目来布置子视图,则可以完成此操作
Use the dataSource method cellForItemAtIndexPath
and run a switch
case on each indexPath.item
. 使用dataSource方法cellForItemAtIndexPath
并在每个indexPath.item
上运行一个switch
案例。 Set your unique views for each item and return the cell. 为每个项目设置唯一的视图并返回单元格。
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithIdentifier:CellIdentifier atIndexPath:indexPath];
switch (indexPath.item) {
case 0:
//add unique views
break;
case 1:
//add unique views
break;
case 2:
//add unique views
break;
default:
break;
return cell;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.