I am working on putting a checkbox in every row of a table view. When I tap a row, its value should get saved into an array, on tap of another row, its value should likewise get saved to the same array, and on a tap of the same row, the value should get deleted from the array.
Please suggest to me how to implement this one. I was using the following code in didSelectRowAtIndexPath method but I was not able to do it.
if([arrData count]==0)
{
strlast = [arrName objectAtIndex:indexPath.row];
[arrData addObject:strlast];
NSLog(@"string checked in arrData %@",strlast);
}
else
{
for(int i = 0 ;i < [arrData count]; i++)
{
NSLog(@"[arrData count]:%d",[arrData count]);
strSelected = [arrName objectAtIndex:indexPath.row];
NSLog(@"strSelected:%@",strSelected);
for(int i = 0 ;i < [arrData count]; i++)
{
if([strSelected caseInsensitiveCompare:[arrData objectAtIndex:i]])
{
[arrData addObject:strSelected];
NSLog(@"arrData:%@",arrData);
}
}
}
}
list is the array name which contains all the data that is viewed in tableview replace it with your own array name
Suppose tableArray is your array in which values are inserted and deleted.
in .h file
in .m file in view didload
tableview didselect row method:-
release the array in dealloc
I have tested the code I hope it might help you….