Heyo傢伙NString值被賽格瑞(目標C)
所以我丟失後或多或少的新目標C和得到,而我似乎無法來解決問題。
我創建了一個名爲「學生」的班,名字都是姓氏等等。所有這些學生都被放入NSMutableArray
(從JSON創建之前,似乎沒有問題)。然後將所有學生的姓名放入ListView
。之後當點擊一個名字時(segue通過對象),應該看到所述學生的詳細信息(即他的全名,他的ID,他的街道)。 問題是學生對象的所有字符串值似乎都丟失了。 我檢查了所有的學生對象都工作得很好。我認爲問題出在我學生課的@property上。
任何意見和建議表示讚賞
這是student.h的摘錄至於說只有字符串值迷路時,INT(這裏的PLZ值)保持正確的
@property (nonatomic, weak)NSString *lastname;
@property (nonatomic, weak)NSString *surname;
@property (nonatomic, weak)NSString *street;
@property (nonatomic, assign)int plz;
編輯: 這裏是我解析我的json的地方。
for (NSDictionary *dic in jsonArray){
NSNumber *identity = [dic valueForKey:@"id"] ;
NSString *firstName = (NSString*) [dic valueForKey:@"first_name"];
NSString *lastName = (NSString*) [dic valueForKey:@"last_name"];
NSString *street = (NSString*) [dic valueForKey:@"street"];
NSNumber *plz = [dic valueForKey:@"plz"] ;
NSString *birth = (NSString*) [dic valueForKey:@"date_of_birth"];
NSArray *bills = dic[@"bills"];
NSArray *hours = dic[@"hours"];
NSLog(@"First %@",firstName);
Student *student = [[Student alloc]initWithLastName:lastName withSurname:firstName withStreet:street withPLZ:plz withOrt:@"Uitikon" withBirthDate:birth withOccupation:@"Schüler"];
[ApprenticeList addObject:student];
}
編輯2:
我發現該字符串值獲得連SEGUE之前丟失。所有這些對象在
ViewDidLoad
創建的,但在
prepareforsegue
所有的值是媒體鏈接空(除INT)。所以如果學生工作的對象是
ViewdidLoad
唯一的地方
字符串,集字典和數組具有可變和不可變的版本。在大多數情況下,對這些屬性使用複製而不是強制是個好主意。你應該在這裏問自己的問題是「爲什麼使用弱點」? – Abizern 2015-03-08 22:31:47
你的init方法看起來像什麼? – Sunkas 2015-03-09 07:22:10
確定您的字符串在設置爲[dic valueForKey:@「first_name」]後不爲零; ? – Sunkas 2015-03-09 07:39:33