gpt4 book ai didi

objective-c - 将字符串添加到数组

转载 作者:行者123 更新时间:2023-11-30 14:24:16 25 4
gpt4 key购买 nike

-(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”数组为空,但我不知道为什么!有什么建议吗?

最佳答案

确保像这样初始化数组(在 viewDidLoad 函数中):

self.chosenSports = [[NSMutableArray alloc] initWith...];

关于objective-c - 将字符串添加到数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12014501/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com