J'essaie de vérifier les éléments d'une visionnable, mais j'ai deux difficultés: 1. Je ne peux pas sélectionner le premier élément 2. si je sélectionne le 2ème et 3ème élément par exemple, cela sera également placer une coche près de la 5ème et 7ème et 9ème et 10ème etc etcCase à cocher pour UITableView
Voici mon code:
#pragma mark -
#pragma mark Table View Data Source Methods
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section {
return [self.listArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CustomCellIdentifier = @"CustomCellIdentifier";
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CustomCellIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
for (id oneObject in nib)
if ([oneObject isKindOfClass:[CustomCell class]]) {
cell = (CustomCell *)oneObject;
}
}
NSUInteger row = [indexPath row];
if ([selectedArray containsObject:cell])
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else {
cell.accessoryType = UITableViewCellAccessoryNone;
}
[cell reloadInputViews];
return cell;
}
- (NSIndexPath *)tableView:(UITableView *)tableView
willSelectRowAtIndexPath:(NSIndexPath *) indexPath{
NSUInteger row = [indexPath row];
if (row == 0)
return nil;
return indexPath;
}
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger row = [indexPath row];
UITableViewCell *c = [tableView cellForRowAtIndexPath:indexPath];
if ([selectedArray containsObject:c])
{
c.accessoryType = UITableViewCellAccessoryNone;
[selectedArray removeObject:c];
[selectedIndexes removeObject:[NSNumber numberWithInt:row]];
}
else {
c.accessoryType = UITableViewCellAccessoryCheckmark;
[selectedArray addObject:c];
[selectedIndexes addObject:[NSNumber numberWithInt:row]];
}
}
- (CGFloat) tableView:(UITableView *)tableView
heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return kTableViewRowHeight;
}
- (void)refreshDisplay:(UITableView *)tableView {
[tableView reloadData];
}
J'ai essayé d'utiliser
NSString *identifier = [NSString stringWithFormat:@"Cell %d", indexPath.row];
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:identifier];
à la place, mais qui a fait disparaître la coche lors du défilement
merci pour la réponse, quelles sont les alternatives à l'utilisation de dequeueReusableCellIdentifier s'il vous plaît? – Lilz