dimanche 28 juin 2015

Add Object to NSMutableArray even it is check marked

I try to add the cell.textlabel.text to an NSMutableArray even it is check marked. I do this with following code:

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

    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

    if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
    else{
        cell.accessoryType = UITableViewCellAccessoryCheckmark;

        self.selectedDays = [[NSMutableArray alloc] init];
        [self.selectedDays addObject:cell.textLabel.text];

        NSLog(@"%@", self.selectedDays);

    }
}

But it does not add, but replace.

    2015-06-28 xx:xx:xx xxxx - xxxx[xxx:xxx] (
    Monday
    )
    2015-06-28 xx:xx:xx xxxx - xxxx[xxx:xxx] (
    Tuesday
    )
    2015-06-28 xx:xx:xx xxxx - xxxx[xxx:xxx] (
    Wednesday
    )

Aucun commentaire:

Enregistrer un commentaire