多选到数组。
Posted
技术标签:
【中文标题】多选到数组。【英文标题】:Multiple selection to array. 【发布时间】:2016-02-29 08:12:01 【问题描述】:我的问题是我将玩家从数据库加载到 UITableView,我想将这些玩家存储在数组中,但我提供了多项选择。接下来我想将此信息保存到数据库。我已经完成了 DB 层,所以只需要有关如何将多个选定的播放器存储到数组的信息。
【问题讨论】:
请阅读how to ask good questions 并尝试编辑您的问题。有了高质量的问题,您将更快地获得更好的答案。谢谢! ***.com/questions/23727255/…的可能重复 【参考方案1】:- (void)viewDidLoad
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.cellSelected = [NSMutableArray array];
self.selectedItems = [NSMutableArray array];
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
//Cell Initialisation here
if ([self.cellSelected containsObject:indexPath])
cell.accessoryType = UITableViewCellAccessoryCheckmark;
else
cell.accessoryType = UITableViewCellAccessoryNone;
return cell;
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
[tableView deselectRowAtIndexPath:indexPath animated:YES];
//if you want only one cell to be selected use a local NSIndexPath property instead of array. and use the code below
//self.selectedIndexPath = indexPath;
//the below code will allow multiple selection
if ([self.cellSelected containsObject:indexPath])
[self.cellSelected removeObject:indexPath];
[self.selectedItems removeObject:[self.selectedItems indexOfObject:[self.dataArray objectAtIndex:indexPath.row]]];
else
[self.cellSelected addObject:indexPath];
[self.selectedItems addObject:[self.dataArray objectAtIndex:indexPath.row]];
[tableView reloadData];
您的数据数组保存数据库中的数据(整体球员信息)的位置。 selectedItems 数组包含所选玩家信息的详细信息。 希望这会有所帮助:)
【讨论】:
[self.selectedItems removeObject:[self.selectedItems indexOfObject:[self.dataArray objectAtIndex:indexPath.row]]]; - 它为将 NSUInteger 发送到 id_Nonnull 类型的参数的指针提供 incimpatible int以上是关于多选到数组。的主要内容,如果未能解决你的问题,请参考以下文章