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 arrD开发者_运维技巧ata
.
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.
}
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];
精彩评论