-(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" 配列が空であることを示していますが、その理由はわかりません! 助言がありますか?