我有一个可变数组,其中数据是动态生成的。为此,我有一个UITextField
和一个添加UIButton
。 UITextField
仅接受数字数据。
当我点击添加按钮时,数据输入如下。
[1,5,6,2,1,5,3,4,........等..
下一个和上一个有两个按钮。
因此,我想要的是,当我单击上一个按钮时,输入的数据必须以相反的顺序顺序显示,并且如果单击下一个按钮,则必须向前显示它。
最佳答案
您需要按住索引点才能获得此值。通过单击上一个和下一个按钮来递增和递减索引,
- (IBAction)previousClicked:(id)sender {
if (index != 0) {
index--;
self.inputTextField.text = [self.dataArray objectAtIndex:index];
}
}
- (IBAction)addCLicked:(id)sender {
[self.dataArray addObject:[NSString stringWithFormat:@"%@",self.inputTextField.text]];
index = self.dataArray.count;
self.inputTextField.text = @"";
}
- (IBAction)nextClicked:(id)sender {
if (index < self.dataArray.count) {
self.inputTextField.text = [self.dataArray objectAtIndex:index];
index++;
}
}
关于ios - 单击按钮获取数组元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25459924/