这是我的代码:
NSMutableArray *ratings = [[NSMutableArray alloc] init];
NSMutableDictionary *eachRating = [[NSMutableDictionary alloc] init];
for (UIView *subview in self.rateServiceView.subviews) {
if ([subview isKindOfClass:[RSTapRateView class]]) {
RSTapRateView *rs = (RSTapRateView *)subview;
[eachRating setObject:rs.rateId forKey:@"iRatingId"];
[eachRating setObject:[NSNumber numberWithInt:rs.rating] forKey:@"iRate"];
[ratings addObject:eachRating];
}
}
而不是获取这些值:
{
iRate = 1;
iRatingId = 1;
},
{
iRate = 5;
iRatingId = 2;
},
{
iRate = 2;
iRatingId = 3;
}
我得到这些值:
{
iRate = 2;
iRatingId = 3;
},
{
iRate = 2;
iRatingId = 3;
},
{
iRate = 2;
iRatingId = 3;
}
当我记录每次迭代的结果时,最后一个对象会替换所有现有对象并为自己添加一个新对象。