gpt4 book ai didi

ios - didDeSelectRowAtIndexPath 没有在 objective-c 中被调用

转载 作者:行者123 更新时间:2023-12-01 19:56:30 26 4
gpt4 key购买 nike

我是 iOS 新手,在选择和取消选择表格 View 单元格时遇到问题。对于取消选择,我使用了 didDeSelectRowAtIndexPath 但它没有被调用

我的代码是这样的

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
cell.textLabel.text=[NSString stringWithFormat:@"%@",[reportshortActivityarray objectAtIndex:indexPath.row]];

if([Selectedarray containsObject:[reportshortActivityarray objectAtIndex:indexPath.row]])
{
[cell setAccessoryType:UITableViewCellAccessoryCheckmark];
}
else
{
[cell setAccessoryType:UITableViewCellAccessoryNone];
}

return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [activitytable cellForRowAtIndexPath:indexPath];

if(![Selectedarray containsObject:[reportshortActivityarray objectAtIndex:indexPath.row]]){
[Selectedarray addObject:[reportshortActivityarray objectAtIndex:indexPath.row]];
txtactivity.text = [Selectedarray componentsJoinedByString:@","];
DefaultActivityString=txtactivity.text;
}

NSLog(@"Selected Value =%@",txtactivity.text);

if(![SelectedIDarray containsObject:[reportidActivityarray objectAtIndex:indexPath.row]]){
[SelectedIDarray addObject:[reportidActivityarray objectAtIndex:indexPath.row]];
lblactivity.text = [SelectedIDarray componentsJoinedByString:@","];
}

NSLog(@"Selected Value =%@",lblactivity.text);

if (cell.selected) {
// ... Uncheck
[activitytable deselectRowAtIndexPath:indexPath animated:YES];
}


[[activitytable cellForRowAtIndexPath:indexPath] setAccessoryType:UITableViewCellAccessoryCheckmark];
activitytable.hidden=NO;
}

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


if([Selectedarray containsObject:[reportshortActivityarray objectAtIndex:indexPath.row]]){
[Selectedarray removeObject:[reportshortActivityarray objectAtIndex:indexPath.row]];
txtactivity.text = [Selectedarray componentsJoinedByString:@","];
}

if([SelectedIDarray containsObject:[reportidActivityarray objectAtIndex:indexPath.row]]){
[SelectedIDarray removeObject:[reportidActivityarray objectAtIndex:indexPath.row]];
lblactivity.text = [SelectedIDarray componentsJoinedByString:@","];
}
NSLog(@"Selected Value =%@",lblactivity.text);

[[activitytable cellForRowAtIndexPath:indexPath] setAccessoryType:UITableViewCellAccessoryNone];
activitytable.hidden=NO;
}

我正在使用此代码来选择和取消选择它正确选择但不取消选择。

enter image description here

如图所示,我可以选择该行但无法取消选择它。

最佳答案

强烈建议使用代码完成。这会给你正确的拼写(大小写很重要!):
...didDeselect...
注意小写 小号

关于ios - didDeSelectRowAtIndexPath 没有在 objective-c 中被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42314148/

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