mercredi 24 juin 2015

iOS tableView multiple selection

Many of the ways and methods out there to select multiple rows is either deprecated or doesn't work.

I simply want to select multiple rows in didSelectRowAtIndexPath and save them into NSUserDefault.

This is my code:

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

NotificationsTableViewCell *cell = (NotificationsTableViewCell*)[tableView cellForRowAtIndexPath:indexPath];

//set clicked icon after row selected
cell.imgIcon.image=[UIImage imageNamed:@"select-icon"];

//notification id for selected row
Notifications* selected = notifications[indexPath.section];
selectedGroup = selected.NotificationsId;

//save it in nsuserdefaults
[[NSUserDefaults standardUserDefaults] setObject:selectedGroup forKey:@"notificationSelectedID"];

}

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

//deselect the row

}

Note: I am using latest xCode SDK 8.

Thank you for your helps.

See more ..

Aucun commentaire:

Enregistrer un commentaire