作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
实际上我已经使用了两个 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/
我是一名优秀的程序员,十分优秀!