1

My problem is that I load players from database to UITableView and i want to store this players in Array but I provide multiple selection. Next I want so save this information to DB. I have done DB layer so just need information how to store this multiple selected players to array.

hds
  • 33
  • 1
  • 8
  • Please read about [how to ask good questions](//stackoverflow.com/help/how-to-ask) and try to edit your question. With high quality questions you will receive better answers faster. Thanks! – Tobi Nary Feb 29 '16 at 08:12
  • Possible duplicate of http://stackoverflow.com/questions/23727255/multiple-checkmark-when-row-selected-in-uitableview-ios – Milap Kundalia Feb 29 '16 at 17:52

1 Answers1

0
- (void)viewDidLoad
{
   [super viewDidLoad];

 // Do any additional setup after loading the view, typically from a nib.
 self.cellSelected = [NSMutableArray array];
 self.selectedItems = [NSMutableArray array];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
   //Cell Initialisation here

if ([self.cellSelected containsObject:indexPath])
{
  cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
{
  cell.accessoryType = UITableViewCellAccessoryNone;

}
 return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

[tableView deselectRowAtIndexPath:indexPath animated:YES];
//if you want only one cell to be selected use a local NSIndexPath property instead of array. and use the code below

//self.selectedIndexPath = indexPath;

//the below code will allow multiple selection
if ([self.cellSelected containsObject:indexPath])
{
  [self.cellSelected removeObject:indexPath];
  [self.selectedItems removeObject:[self.selectedItems indexOfObject:[self.dataArray objectAtIndex:indexPath.row]]];
}
else
{
   [self.cellSelected addObject:indexPath];
   [self.selectedItems addObject:[self.dataArray objectAtIndex:indexPath.row]];
}
[tableView reloadData];
}

Where your data array hold data from database (Whole players information). selectedItems array contains the details of selected player info. Hope this helps :)

Deepak Pillai
  • 345
  • 2
  • 3
  • 12
  • [self.selectedItems removeObject:[self.selectedItems indexOfObject:[self.dataArray objectAtIndex:indexPath.row]]]; - It gives incimpatible int to pointer sending NSUInteger to parametr of type id_Nonnull – hds Mar 01 '16 at 14:07