gpt4 book ai didi

iOS tableView 多选

转载 作者:行者123 更新时间:2023-11-29 01:54:37 29 4
gpt4 key购买 nike

许多用于选择多行的方式和方法要么已弃用,要么不起作用。

我只想在 didSelectRowAtIndexPath 中选择多行并将它们保存到 Array 或 NSUserDefault 中。这种情况下我选择了 NSUserDefault 但我愿意将其更改为 Array。

这是我的代码:

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

NotificationsTableViewCell *cell = (NotificationsTableViewCell*)[tableView cellForRowAtIndexPath:indexPath];

//set clicked icon after row selected
cell.imgIcon.image=[UIImage imageNamed:@"select-icon"];

//notification id for selected row
Notifications* selected = notifications[indexPath.section];
selectedGroup = selected.NotificationsId;

//save it in nsuserdefaults
[[NSUserDefaults standardUserDefaults] setObject:selectedGroup forKey:@"notificationSelectedID"];

}

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

//deselect the row

}

注意:我使用的是最新的 Xcode SDK 8。

感谢您的帮助。

最佳答案

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

NotificationsTableViewCell *cell = (NotificationsTableViewCell*)[tableView cellForRowAtIndexPath:indexPath];

// do your logic with following condition

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

}
else
{

cell.accessoryType = UITableViewCellAccessoryNone;

}

}

关于iOS tableView 多选,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31019888/

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