以下是我的代码:
First Category.h
#import <Foundation/Foundation.h>
@interface Category : NSObject {
NSMutableArray *items;
NSString *name;
NSString *description;
NSString *imagePath;
NSString *id;
}
@property (nonatomic, retain) NSMutableArray *items;
@property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) NSString *description;
@property (nonatomic, retain) NSString *id;
@property (nonatomic, retain) NSString *imagePath;
-(id)init;
-(UIImage*)getImage;
@end
控制器:
- (id)initWithCategory:(Category *)categoryItem
{
self = [super init];
if (self) {
self.category = categoryItem;
}
return self;
}
在头文件中:
@property (nonatomic, retain) Category *category;
- (id)initWithCategory:(Category *)categoryItem;
我希望self.category和categoryItem完全相同。
更新:我很抱歉,错误不在这里。谢谢你的帮助。
答案 0 :(得分:0)
如果category
是属性,则应使用self.category
。
但是,假设您使用诸如_category
(@synthesize category = _category
)之类的支持ivar合成了您的属性,那么您应该参考ivar并在init方法中使用_category
。