gpt4 book ai didi

ios - 如何在 Collection View 中对单元格单击创建按钮操作

转载 作者:行者123 更新时间:2023-11-29 10:42:26 24 4
gpt4 key购买 nike

实际上我已经使用了两个 Collection View Controller 。在第一个 Collection View Controller 中,我已经传递了图像数组。单击一个图像,我想显示另一个 Collection View Controller 。如何执行此操作...请给我建议。

- (void)viewDidLoad
{
[super viewDidLoad];

recipeImages = [NSArray arrayWithObjects:@"angry_birds_cake.jpg", @"creme_brelee.jpg", @"egg_benedict.jpg", @"full_breakfast.jpg", @"green_tea.jpg", @"ham_and_cheese_panini.jpg", @"ham_and_egg_sandwich.jpg", @"hamburger.jpg", @"instant_noodle_with_egg.jpg", nil];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return recipeImages.count;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{

}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = @"Cell";

UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];

UIImageView *recipeImageView = (UIImageView *)[cell viewWithTag:100];
recipeImageView.image = [UIImage imageNamed:[recipeImages objectAtIndex:indexPath.row]];
cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"photo-frame.png"]];
for (UIView *view in cell.subviews) {
if ([view isKindOfClass:[UILabel class]]) {
[view removeFromSuperview];
}
}


UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(5, 0, 150, 170)];//Set the frame as per your requirement.
label.font=[UIFont systemFontOfSize:10];

[label setText:[NSString stringWithFormat:@"%@",[categoryArray objectAtIndex:indexPath.row]]];
[cell addSubview:label];
//NSLog(@"hiiiii");


return cell;

最佳答案

如果您想在另一个 View Controller 中显示第二个 Collection View ,只需将包含 Collection View 的 View Controller 推送到 didSelectItemAtIndexPath: 中即可。

如果你想在同一个 View Controller 中显示第二个 Collection View ,你可以创建两个 Collection View 并将第二个设置为隐藏。然后在 didSelectItemAtIndexPath: 中,您可以将第二个 Collection View 设置为显示,将第一个设置为隐藏。这将通过 collectionView.hidden = YES or NO 完成。

关于ios - 如何在 Collection View 中对单元格单击创建按钮操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23880795/

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