这段代码出了什么问题,因为我试图从NSDictionary对象的NSArray中获取NSDictionary对象,但它会进入无限循环。
- (void)updateFieldsWithData:(NSArray *)items {
// NSLog(@"updateFieldsWithData (%d)", [items count]);
for ( NSDictionary * item in items ) { // add rows to the item table
[tfPhoneNumber setText:[item valueForKey:kPhoneNumberKey]];
[tfFirstName setText:[item valueForKey:kFirstNameKey]];
[tfLastName setText:[item valueForKey:kLastNameKey]];
[tfEmailAddress setText:[item valueForKey:kEmailKey]];
[tfStreet setText:[item valueForKey:kStreetKey]];
[tfCity setText:[item valueForKey:kCityKey]];
[tfState setText:[item valueForKey:kStateKey]];
[tfZipCode setText:[item valueForKey:kZipCodeKey]];
}
}
答案 0 :(得分:1)
正如@Chris所说,你的for
循环可能不是你的代码无限循环的原因。
我习惯于添加此代码以了解调用我的函数的内容。只需将其放在函数updateFieldsWithData:
NSString *sourceString = [[NSThread callStackSymbols] objectAtIndex:1];
NSCharacterSet *separatorSet = [NSCharacterSet characterSetWithCharactersInString:@" -[]+?.,"];
NSMutableArray *array = [NSMutableArray arrayWithArray:[sourceString componentsSeparatedByCharactersInSet:separatorSet]];
[array removeObject:@""];
NSLog(@"Class caller = %@", [array objectAtIndex:3]);
NSLog(@"Function caller = %@", [array objectAtIndex:4]);