我已經創建了一個自定義視圖,並在自定義視圖內,有一個imageView。當我將控件傳遞給customView並打印出我的imageView時,它將返回null。不知道爲什麼。UIImageView返回零自定義視圖
.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。任何想法爲什麼?
在IB或代碼創建的視圖?如果在代碼中創建,你是否將其添加到視圖?你掛了電源插座嗎? –
'galleryImageView'本身是否返回null或其圖像是否爲null? –
我在IB創建了一個視圖,並提出了自定義類= GalleryImage – lakesh