2012-03-26 89 views
0

下面是我的代码:如何将对象分配给IOS中的本地对象?

首先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; 

我想自我.category和categoryItem将完全相同。

更新:我很抱歉,错误不是从这里。感谢您的帮助。

+0

'无法赋值'是什么意思?任何形式的警告或标志? – CodaFi 2012-03-26 21:30:29

+0

值不一样。我希望该类别对象将是categoryItem。 – Burak 2012-03-26 21:36:38

+0

我不相信'category'在'initWithCategory'中的赋值后不等于'categoryItem'。你怎么看? – mattjgalloway 2012-03-26 22:05:15

回答

0

如果category是属性,那么你应该使用self.category

但是,假设你已经合成了你的财产有后盾伊娃如_category@synthesize category = _category),那么你就应该指的是伊娃和init方法使用_category

相关问题