我创建了一个customView,在customView 里面有一个imageView。当我将控件传递给 customView 并打印出我的 imageView 时,它返回 null。不知道为什么。
。H
#import <UIKit/UIKit.h>
@interface GalleryImage : UIView
{
IBOutlet UIImageView *galleryImageView;
}
- (id)initWithImage:(UIImage*) image;
@property(strong,nonatomic) IBOutlet UIImage *galleryImage;
@end
.m
#import "GalleryImage.h"
@implementation GalleryImage
@synthesize galleryImage;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
- (id)initWithImage:(UIImage*) image
{
self = [super init];
if (self) {
galleryImage = image;
[galleryImageView setImage:galleryImage];
}
return self;
}
以这种方式传递控制:
UIImage *infoImage = [UIImage imageNamed:imageName];
GalleryImage *galleryItem = [[GalleryImage alloc] initWithImage:infoImage];
但我的galleryImageView 返回null。知道为什么吗?