ios:For循环变为无限

时间:2013-11-12 13:53:54

标签: ios objective-c ios7 nsarray nsdictionary

这段代码出了什么问题,因为我试图从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]];
    }
}

enter image description here

1 个答案:

答案 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]);