Gati Gati - 7 months ago 50
iOS Question

Get Array element on button click

I have one mutable array in which data entered dynamically. For that i have one textfield and one add button. textfield accepts only numeric data.

When i click add button data entered as below.

[1,5,6,2,1,5,3,4,........ and so on..

There is two button next and previous.

So, what i want is when i click previous button the entered data which must be display sequentially in reverse order and same time if click next button it must be display in forward direction.


You need to hold the index point to get this.increment and decrement the index with previous and next button clicks,

- (IBAction)previousClicked:(id)sender {
    if (index != 0) {
        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];