这里我使用XIB在tableview的每个部分加载不同的集合视图。这是我在tableview单元格中的Viewcontroller和collectionview单元的设计结构。
我尝试了一些东西,供您参考。
Tableviewcell.m
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
[collection registerNib:[UINib nibWithNibName:@"ScheduleCell" bundle:nil] forCellWithReuseIdentifier:@"cellid"];
[collection registerNib:[UINib nibWithNibName:@"ResultCell" bundle:nil] forCellWithReuseIdentifier:@"cellno"];
[collection registerNib:[UINib nibWithNibName:@"ResultCell1" bundle:nil] forCellWithReuseIdentifier:@"cellno1"];
[collection registerNib:[UINib nibWithNibName:@"ResultCell2" bundle:nil] forCellWithReuseIdentifier:@"cellno2"];
[collection registerNib:[UINib nibWithNibName:@"ResultCell3" bundle:nil] forCellWithReuseIdentifier:@"cellno3"];
}
-(void)configureCell:(id <UICollectionViewDelegate,UICollectionViewDataSource>)delegate andIndex:(NSIndexPath *)indexPath andTitile:(NSString *)title{
collection.dataSource = delegate;
collection.delegate = delegate;
collection.tag = indexPath.section;
NSLog(@"collectionArray %ld",(long)collection.tag);
dispatch_async(dispatch_get_main_queue(), ^{
[self.collection reloadData];
});
}
Viewcontroller.m
我从下面的委托
调用了配置单元格方法- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
[Tablecell configureCell:self andIndex:indexPath andTitile:@"Events"];
}
所有人都被调用但我无法从他们相应的委托中获取collectionview.tag。所以,我无法在这里加载不同的collectionview单元格。如果我错了,任何人都会指引我。
欢迎您在swift或Objective-c
中提出建议我有加载不同单元格的问题。这里collectionView.tag总是为零。当在configurecell
方法中分配标记时,它不分配。因为没有分配collection
内存。我无法加载不同的单元格。
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
UICollectionViewCell* ColCell;
if (collectionView.tag == 1) {
ScheduleCell* cell = (ScheduleCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"cellid" forIndexPath:indexPath];
cell.eventNamelbl.text = @"ScheduleCell";
ColCell = cell;
}
else if (collectionView.tag == 2){
ResultCell* cell = (ResultCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"cellno" forIndexPath:indexPath];
cell.resultlbl.text = @"ResultCell";
ColCell = cell;
}
else if (collectionView.tag == 3){
ResultCell1* cell = (ResultCell1 *)[collectionView dequeueReusableCellWithReuseIdentifier:@"cellno1" forIndexPath:indexPath];
cell.resultlbl.text = @"ResultCell";
ColCell = cell;
}
else if (collectionView.tag == 4){
ResultCell2* cell = (ResultCell2 *)[collectionView dequeueReusableCellWithReuseIdentifier:@"cellno2" forIndexPath:indexPath];
cell.resultlbl.text = @"ResultCell";
ColCell = cell;
}
else if (collectionView.tag == 5){
ResultCell3* cell = (ResultCell3 *)[collectionView dequeueReusableCellWithReuseIdentifier:@"cellno3" forIndexPath:indexPath];
cell.resultlbl.text = @"ResultCell";
ColCell = cell;
}
return ColCell;
}