我有一个包含多个产品的 NSMutableArray。每个产品都有数量。单击步进器时,我想更新相关产品的数量。但是我所有的产品(整个 NSMutableArray)都更新了步进器的数量。
NSInteger index = stepper.tag;
Product *p = [products objectAtIndex:index];
p.amount = [NSNumber numberWithDouble:stepper.value];
// UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"%d", stepper.tag] message:@"test" delegate:nil cancelButtonTitle:@"ok"otherButtonTitles:nil];
// [alert show];
for (Product *p in products) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"%@", p.amount] message:p.name delegate:nil cancelButtonTitle:@"ok"otherButtonTitles:nil];
[alert show];
}
有没有人有办法解决吗?