gpt4 book ai didi

ios - 如何使两个 Collection View 出现在同一个 View Controller 上?

转载 作者:行者123 更新时间:2023-12-02 03:03:56 25 4
gpt4 key购买 nike

我想在同一页面中有两个 UICollectionView 。两个 UICollectionView 将根据需要显示不同的数据。我怎样才能做到这一点?提前致谢。

- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath
{

static NSString *cellIdentifierHall2 = @"hall2";

/* Uncomment this block to use subclass-based cells */
timeCell *cell = (timeCell *)[myCollectionViewHall2 dequeueReusableCellWithReuseIdentifier:cellIdentifierHall2 forIndexPath:indexPath];

[cell.timeButton setTitle:[[allSimilarMutableArray valueForKey:@"showTime"] objectAtIndex:indexPath.item] forState:UIControlStateNormal];


return cell;

}

- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath
{

static NSString *cellIdentifierHall3 = @"hall3";

/* Uncomment this block to use subclass-based cells */
timeCell *cell = (timeCell *)[myCollectionViewHall3 dequeueReusableCellWithReuseIdentifier:cellIdentifierHall3 forIndexPath:indexPath];

[cell.timeButton setTitle:[[allSimilarMutableArray valueForKey:@"showTime"] objectAtIndex:indexPath.item] forState:UIControlStateNormal];


return cell;

}

最佳答案

您可以通过区分“cellForItemAtIndexPath”来执行相同的操作

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {

if (collectionView == self.collectiveview1) {

UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CollectionCell" forIndexPath:indexPath];
UILabel *titleLabel = (UILabel *)[cell viewWithTag:100];
[titleLabel setText:celldata];

UIImageView *imageView = (UIImageView *)[cell viewWithTag:200];
[imageView setImage:[UIImage imageNamed:connimage]];

return cell;

} else {

static NSString *cellIdentifier = @"FollowCell";
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];

UILabel *titleLabel = (UILabel *)[cell viewWithTag:100];
[titleLabel setText:celldata];

UIImageView *imageView = (UIImageView *)[cell viewWithTag:200];
[imageView setImage:[UIImage imageNamed:cellImage]];

return cell;

}
}

希望有帮助。

关于ios - 如何使两个 Collection View 出现在同一个 View Controller 上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22096378/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com