【问题标题】:Cannot get UIImage to show in a UICollectionViewCell无法让 UIImage 在 UICollectionViewCell 中显示
【发布时间】:2013-05-03 12:25:17
【问题描述】:

我无法在UICollectionViewCell 中设置图像,但是UILabel 可以正常工作。以下是相关代码:

// CatagoryViewCell.m
#import "CatagoryViewCell.h"

@implementation CatagoryViewCell
@synthesize nameLabel;

- (void)setImage:(UIImage *)image
{
    [catagoryCellImage setImage:image];
}

@end

// ViewController.m
UIImage *image = [UIImage imageNamed:@"canon.jpg"];
[cell setImage:image];

return cell;

谢谢!

【问题讨论】:

  • 试试 catagoryCellImage.image=image;而是 [categoryCellImage setImage:image];

标签: iphone objective-c uiimageview uiimage uicollectionview


【解决方案1】:

试试下面的代码,

//cell.h

#import <UIKit/UIKit.h>

@interface detail : UITableViewCell 
@property (nonatomic, retain) IBOutlet UIButton *check;
@property (nonatomic, retain) IBOutlet UIImageView *img;
@end


// cell.m

#import "cell.h"

@implementation detail

@synthesize option, img;



 // ViewController.m

    cell.img.image= [UIImage imageNamed:@"canon.jpg"];

    return cell;

【讨论】:

  • 也不行,谢谢。它是 UICollectionViewCell,而不是 UITableViewCell。这会有所作为吗?
  • 重点是,您应该将 UIImageView 作为子视图添加到您的 UICollectionViewCell 子类的 -contentView 属性中。也许您忘记将 UIImageView 添加为子视图?
  • @art-divin 是的,我还没有将它添加为子视图,我会尝试的。谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-04
  • 2015-07-31
  • 2019-04-18
相关资源
最近更新 更多