Objective-C - 改变NSMutableArray的特定元素
NSMutableArray修改元素, 使用-insertObject: atIndex: 和-replaceObjectAtIndex: withObject: 都可以, 即通过插入(insert)和替换(replace)可以实现.
示例:
// 减少按钮监听
- (void) onSubBtnPressed:(UIButton*) sender {
NIDPRINTMETHODNAME();
NSInteger times = [[_serviceNumList objectAtIndex:_servicePos] integerValue];
if (times <= 1) {
return;
}
times--; // 减少
// 改变数组数据
[_serviceNumList replaceObjectAtIndex:_servicePos withObject:[NSNumber numberWithInteger:times]];
// 设置数据
UITextField *mo = [_timesFieldArray objectAtIndex:_servicePos];
NSAttributedString* timesText =[[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%ld", (long)[[_serviceNumList objectAtIndex:_servicePos] integerValue]]]; // 设置文字
[mo setAttributedText:timesText];
_totalPrice = (float)([_goodsList[_servicePos][@"Price"] floatValue]/100.0)*[[_serviceNumList objectAtIndex:_servicePos] integerValue];
[_totalPriceLabel setText:[NSString stringWithFormat:@"%0.1f", _totalPrice]];
}
声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
- 上一篇: Windows编程 - 遍历所有进程(exe) 代码(C++)
- 下一篇: Gensim 安装