我有一个名为Company的类,我想重写init
方法。我想在此方法中包含公司徽标。我试过这个:
- (id)init
{
self = [super init];
if (self) {
self.companyName = @"";
self.companyLogo = nil;
self.companyDesc = @"";
self.companyYear = 0;
}
return self;
}
- (id) initWithCompanyName: (NSString*)companyName companyLogo: ***(UIImage*)companyLogo***
companyDescription: (NSString*)companyDesc foundationYear: (NSInteger)foundationYear
{
self = [self init];
if(self)
{
self.companyName = companyName;
self.companyLogo = companyLogo;
self.companyDesc = companyDesc;
self.companyYear = foundationYear;
}
return self;
}
显然它不能是UIImage。那么我该如何在初始化中包含图像?
答案 0 :(得分:2)
使用此调用的类定义可以正常工作:
UIImage *logo = [UIImage imageNamed:@"IMG_0424.JPG"];
Company *company = [[Company alloc]initWithCompanyName:@"iPichy" companyLogo:logo companyDesc:@"iPichy APP Development" foundationYear:2010];