標籤:mystra 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]];}
著作權聲明:本文為博主原創文章,未經博主允許不得轉載。
Objective-C - 改變NSMutableArray的特定元素