gpt4 book ai didi

ios - 如何将 textField 的 integerValue 放入数组中?

转载 作者:行者123 更新时间:2023-11-28 21:54:51 24 4
gpt4 key购买 nike

@property NSMutableArray*textFieldsA;

@property NSMutableArray*textFieldsB;

@property NSMutableArray*textFieldsR;

@property NSMutableArray *operandArrayA;

@property NSMutableArray *operandArrayB;

_textFieldsA = @[self.textFieldA0, self.textFieldA1, self.textFieldA2, self.textFieldA3, self.textFieldA4, self.textFieldA5, self.textFieldA6, self.textFieldA7, self.textFieldA8];
_textFieldsB = @[self.textFieldB0, self.textFieldB1, self.textFieldB2, self.textFieldB3, self.textFieldB4, self.textFieldB5, self.textFieldB6, self.textFieldB7, self.textFieldB8];
_textFieldsR = @[self.textFieldR0, self.textFieldR1, self.textFieldR2, self.textFieldR3, self.textFieldR4, self.textFieldR5, self.textFieldR6, self.textFieldR7, self.textFieldR8];

for (int i = 0; i < 9; i++) {
_operandA = [((UITextField*)_textFieldsA[i]).text integerValue];
_operandB = [((UITextField*)_textFieldsB[i]).text integerValue];
[self.arithmetic setOperandA:_operandA operandB:_operandB operator:_operator];
_finalString = [NSString stringWithFormat:@"%d",[self.arithmetic result]];
((UITextField*)_textFieldsR[i]).text = _finalString;
}

我怎样才能把整数值放在

 self.textFieldA0.text , self.textFieldA1.text , self.textFieldA3.text ........self.textFieldA8.text

进入数组(operandArrayA)?

我试过了

 operandArrayA[i] = [((UITextField*)_textFieldsA[i]).text integerValue];

但是不行,我该怎么办?

最佳答案

很遗憾,您不能在 NSArray 中添加原始数据类型。您需要为整数值创建 NSNumber 对象。将此对象存储到一个数组中。

像这样:

NSNumber *number = @([((UITextField*)_textFieldsA[i]).text  integerValue]);
operandArrayA[i] = number;

关于ios - 如何将 textField 的 integerValue 放入数组中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26927644/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com