gpt4 book ai didi

ios - Collection View 单元格显示不显示

转载 作者:行者123 更新时间:2023-11-29 04:11:50 27 4
gpt4 key购买 nike

我有一个collectionview Controller 和一个collectionviewcell。对于collectionviewcell,我有一个自定义类。我正在尝试设置 uiimage,但它不起作用。

提前谢谢您!

我试图设置图像的collectionview Controller 中的方法。

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

static NSString *cellIdentifier=@"Cell";

CollectionVIewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
;
CollectionVIewCell *feederCell = (CollectionVIewCell*)[_availableFilters objectAtIndex:indexPath.row];



cell.labelDisplay.text=feederCell.filterName;
NSLog(@"selected =%@",cell.labelDisplay.text);
if (feederCell.isSelected) {
UIImageView *imageView=[[UIImageView alloc]init];
//process string name
NSString*filePath =[NSString stringWithFormat:@"%@.png",feederCell.filterName];
NSArray* words = [filePath componentsSeparatedByCharactersInSet :[NSCharacterSet whitespaceCharacterSet]];
filePath=[words componentsJoinedByString:@""];
cell.FilePath=filePath;
//image
UIImage *image = [UIImage imageNamed:filePath];
[imageView setFrame:CGRectMake(0, 0, image.size.width, image.size.height)];
[imageView setImage:image];
[cell setIconDisplay:imageView];//setting the image that won't set
}else if(!feederCell.isSelected){
UIImageView *imageView=[[UIImageView alloc]init];
NSString*filePath =[NSString stringWithFormat:@"%@.png",feederCell.filterName];
NSArray* words = [filePath componentsSeparatedByCharactersInSet :[NSCharacterSet whitespaceCharacterSet]];
filePath=[words componentsJoinedByString:@""];
UIImage *image = [UIImage imageNamed:filePath];
[imageView setFrame:CGRectMake(0, 0, image.size.width, image.size.height)];
[imageView setImage:image];
[cell setIconDisplay:imageView];
}

return cell;

.h 文件

//
// CollectionVIewCell.h

#import <UIKit/UIKit.h>

@interface CollectionVIewCell : UICollectionViewCell
@property (strong, nonatomic) IBOutlet UIImageView *IconDisplay;
@property (strong, nonatomic) IBOutlet UILabel *labelDisplay;
@property (assign,nonatomic) BOOL isSelected;
@property (strong,nonatomic)NSString*textName;
@property(strong,nonatomic)NSString*FilePath;

@end

.m文件

//
// CollectionVIewCell.m

#import "CollectionVIewCell.h"

@implementation CollectionVIewCell

- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
_labelDisplay.text=_textName;
_IconDisplay=[[UIImageView alloc]init];
}
return self;
}

@end

最佳答案

您需要将 UIImageView 添加为 subview 。否则它存在但不显示。

关于ios - Collection View 单元格显示不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14300393/

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