我有一个奇怪的问题。
M_DrugListRow具有以下属性:NAME,SEGMENT,ATTRIBUTE,COLORCODE,ID,DESCRIPTION
dict有这些drug_name,segment,attribute,colorcode,..
M_DrugListRow *m= [[M_DrugListRow alloc]initDrugRow:[arr_for_picker objectAtIndex:row] val:0]
[dict setValue:m.NAME forKeyPath:@"drug_name"];
此代码后,dict有M_DrugListRow的键(NAME,SEGMENT,ATTRIBUTE,COLORCODE,DESCRIPTION),而不是他自己的键(名称,段,属性,颜色代码,drug_name) 所以它在我的代码中给出了错误。
如果我将其更改为此代码,则可以:
[dict setValue:[[arr_for_picker objectAtIndex:row]objectForKey:@NAME"] forKeyPath:@"drug_name"];
我太用第一种了。但它没有效率。为什么会发生这种情况?我该如何解决这个问题?
代码: M_DrugListRow.h
@interface M_DrugListRow : M_Drug
-(id)initDrugRow:(M_Drug*)drugModel val:(NSInteger)val
{
self=[super init];
@try {
self=[self initDrug:[NSDictionary dictionaryWithPropertiesOfObject:drugModel]];
liquid =[[NSMutableArray alloc]init];
method =[[NSMutableArray alloc]init];
if(val){
liquid= [DataAccessLiquid drugliquid:[VC_Login getGuid] drug_id:self.ID];
method= [DataAccessMethod:[VC_Login getGuid] drug_id:self.ID];
}
}
@catch (NSException *exception) {
}
@finally {
}
return self;
}
M_Drug.h
-(id)initDrug:(NSDictionary*)par
{
self=[super init];
dict =[[NSDictionary alloc]initWithDictionary:par];
@try {
ATTRIBUTE1= [par valueForKey:@"ATTRIBUTE1"];
NAME= [par valueForKey:@"NAME"];
COLORCODE= [[par valueForKey:@"COLORCODE"]boolValue];
DESCRIPTION= [par valueForKey:@"DESCRIPTION"];
SEGMENT= [par valueForKey:@“SEGMENT”];
ID= [[par valueForKey:@"ID"]integerValue];
}
@catch (NSException *exception) {
}
@finally {
}
return self;
}