-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
BOOL isChecked;
//check if there is checkmark there
if([tableView cellForRowAtIndexPath:indexPath].accessoryType == UITableViewCellAccessoryCheckmark){
isChecked = YES;
}
else {
isChecked = NO;
}
//adds or moves checkmark
if(isChecked == YES){
NSLog(@"Checkmark removed...");
UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];
newCell.accessoryType = UITableViewCellAccessoryNone;
lastIndexPath = indexPath;
}
if(isChecked == NO){
NSLog(@"Checkmark added...");
[chosenSports addObject:[sports objectAtIndex:[indexPath row]]];
NSLog(@"%@",[chosenSports objectAtIndex:0]);
UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];
newCell.accessoryType = UITableViewCellAccessoryCheckmark;
lastIndexPath = indexPath;
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
由于某种原因,我的 NSLog 的结果为 NULL,表明“chosenSports”数组为空,但我不知道为什么!有什么建议么?