首页 > 其他 > 详细

Objective-C - 改变NSMutableArray的特定元素

时间:2017-06-29 13:11:41      阅读:293      评论:0      收藏:0      [点我收藏+]

NSMutableArray改动元素, 使用-insertObject: atIndex: -replaceObjectAtIndex: withObject: 都能够, 即通过插入(insert)和替换(replace)能够实现.
演示样例:

// 降低button监听
- (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]];
}

技术分享

Objective-C - 改变NSMutableArray的特定元素

原文:http://www.cnblogs.com/mfmdaoyou/p/7093811.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!