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
.
Asked
Active
Viewed 142 times
0

Sathyajith Bhat
- 21,321
- 22
- 95
- 134

sujay
- 1,845
- 9
- 34
- 55
2 Answers
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.
}

Chetan Bhalara
- 10,326
- 6
- 32
- 51
-
how can we store the 3 variables for selecting 3 rows – sujay Apr 28 '11 at 07:15
-
Means? Which 3 variables you want to store? – Chetan Bhalara Apr 28 '11 at 07:17
-
according to your example first row data ,2nd row data and 3rd row data , how will io get these 3 variables – sujay Apr 28 '11 at 07:27
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];

Sathyajith Bhat
- 21,321
- 22
- 95
- 134

Aman Aggarwal
- 3,754
- 1
- 19
- 26