簡體   English   中英

集合視圖單元格顯示不顯示

[英]collection view cell display not displaying

我有一個collectionview控制器和一個collectionviewcell。 對於collectionviewcell,我有一個自定義類。 我正在嘗試設置uiimage,但它不起作用。

先感謝您!。

我正在嘗試設置圖像的collectionview控制器中的方法。

-(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添加為子視圖。 否則它存在但不顯示。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM