Iphone 如何显示类中的UIImageView

Iphone 如何显示类中的UIImageView,iphone,ios,cocoa-touch,Iphone,Ios,Cocoa Touch,我有一个名为myClass的类,带有UIImageViewimgView和其他变量。如何在界面生成器中显示该视图 抱歉,如果问题不太准确,我是iOS开发新手。问我任何问题 您需要在myClass.h中将其声明为IBOutlet: @property (retain, nonatomic) IBOutlet UIImageView *imgView; 然后可以将插座连接到interface builder中的属性。有关示例,请参见下图: 首先,您可以将UIImageView拖动到xib文件中,然

我有一个名为
myClass
的类,带有
UIImageView
imgView
和其他变量。如何在界面生成器中显示该视图


抱歉,如果问题不太准确,我是iOS开发新手。问我任何问题

您需要在myClass.h中将其声明为IBOutlet:

@property (retain, nonatomic) IBOutlet UIImageView *imgView;
然后可以将插座连接到interface builder中的属性。有关示例,请参见下图:


首先,您可以将UIImageView拖动到xib文件中,然后连接到IBMOutlet UIImageView成员类。 在编写下面的代码后,请更改图像视图变量。 要显示的图像必须位于资源或支持文件中

- (void)viewDidLoad
{
    [super viewDidLoad];

    NSString *filePath = [[NSBundle mainBundle] pathForResource:imageName ofType:@"jpg"];
    UIImage *image = [UIImage imageWithContentsOfFile:filePath];
    imageView.image = image;

}

如果您使用的是Xcode 4,则可以通过按住control并拖动到相应的.h文件,直接从nib创建插座。