I am trying to add selected rows in to my array.when I am adding second selected row into myArray the first object is replace with second and every time I am getting only one object in myArray.Here is my table didSelectAtIndexPath: method code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (cell.accessoryType == UITableViewCellAccessoryNone)
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
myArray = [[NSMutableArray alloc] init];
[myArray addObject:[Array1 objectAtIndex:indexPath.row]];
NSLog(@"myArray %@",myArray);
}
}
can anyone help me. Thanks in advance
The issue is caused by this line:
You are allocating this array each time when user clicks a cell.
Allocate it in your
viewDidLoad.or Add a condition before allocating like: