0

I have a table view with 3 rows, if I select the first row , the item on the first row get saved in a array variable say arrdata , similarly when I select 2nd and 3rd row , I want it to get saved in the same variable arrData.

2 Answers 2

1

You can use NSMutableArray.

For Ex.

NSMutableArray *arrData = [[NSMutableArray alloc] init];

Now, select the first row from table view

Use [arrData addObject:[first row data]];

For 2nd from table view

Use [arrData addObject:[2nd row data]];

For 3rd from table view

Use [arrData addObject:[3rd row data]];

And you can also add some condition for add data in to arrData, like if 1st row data is added then do't re-add it.

For Ex. When you select 1st row you can add 1, 2nd selection add 2, 3rd selection add 3 like [arrData addObject:@"1"]; etc.

Now, If you want to get data from arrData,

If (arrData.count > 0)
{
    NSString *fData = [arrData objectAtIndex:0]; // Here you get stored data from 1st selected row of table.
}
Sign up to request clarification or add additional context in comments.

3 Comments

how can we store the 3 variables for selecting 3 rows
Means? Which 3 variables you want to store?
according to your example first row data ,2nd row data and 3rd row data , how will io get these 3 variables
0

Create an nsmutable array and add objects by using method addobject

NSMutableArray *arrData =[[NSMutableArray alloc]ini];

On Tableselection method , add the following line

[arrdata addObject:your object];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.