Здравствуйте, я новичок в разработке iPhone. Я пытаюсь добавить данные перемещения из NSDictionary к членам данных вызовов, которые я создал. Когда я «setWeightMeasure», ничего не произошло.добавить данные в мои данные
любые предложения?
код, который не работает:
NSDictionary *responseBodyProfile = [responseBody objectFromJSONString];
NSLog(@"%@",responseBodyProfile);
// the output is :
"{ "profile": {"goal_weight_kg": "77.0000", "height_cm": "179.00",
"height_measure": "Cm", "last_weight_date_int": "15452",
"last_weight_kg": "99.0000", "weight_measure": "Kg" }}""
[responseBody release];
if (responseBodyProfile != nil){
NSDictionary *profile =[responseBodyProfile valueForKey:@"profile"];
NSLog(@"%@\n",[profile objectForKey:@"weight_measure"]);// Output : "kg"
[self.myUser setWeightMeasure:[profile objectForKey:@"weight_measure"]];
NSLog(@"%@", [self.myUser WeightMeasure]); // Output : "(null)"
}
Н файл properyty:
@property (nonatomic, retain) UserData* myUser;
UserData.h:
#import <Foundation/Foundation.h>
@interface UserData : NSObject{
NSString* Weight;
NSString* Height;
NSString* GolWeight;
NSString* WeightMeasure;
}
@property (nonatomic, retain) NSString* Weight;
@property (nonatomic, retain) NSString* Height;
@property (nonatomic, retain) NSString* GolWeight;
@property (nonatomic, retain) NSString* WeightMeasure;
@end
UserData.m
#import "UserData.h"
@implementation UserData
@synthesize Weight, Height, GolWeight, WeightMeasure;
-(id)init{
self.Weight = @"0";
self.Height = @"0";
self.GolWeight = @"0";
self.WeightMeasure = @"0";
return self;
}
-(void)dealloc{
[Weight release];
[Height release];
[GolWeight release];
[WeightMeasure release];
[super dealloc];
}
@end
Прежде всего, когда вы создаете/инициализируете свой объект myUser. можете ли вы просто NSLog (@ "% @", self.myUser.WeightMeasure); И мне не нравится, когда люди не следуют надлежащим правилам кода. Разве вы не думаете, что ваша переменная-член должна начинаться с маленькой буквы, ну, что не имеет значения. –