gpt4 book ai didi

ios - 未选择的 UITableView 行列表

转载 作者:可可西里 更新时间:2023-11-01 05:03:59 24 4
gpt4 key购买 nike

我有以下代码。

NSMutableArray *aList = [[NSMutableArray alloc] init];
for (NSIndexPath *indexPath in tableview1.indexPathsForSelectedRows) {
NSString *r = [NSString stringWithFormat:@"%i",indexPath.row];
[aList addObject:r];
}

所以我得到的是一个被选中的 UITableView 行的列表。有没有一种简单的方法可以获取列表 NOT 选中的行?

感谢您的帮助。

最佳答案

可能有优雅的解决方案,但这会起作用。

    NSMutableArray *allIndexPaths = [@[]mutableCopy];
NSInteger nSections = [self.tableView numberOfSections];
for (int j=0; j<nSections; j++) {
NSInteger nRows = [self.tableView numberOfRowsInSection:j];
for (int i=0; i<nRows; i++) {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:j];
[allIndexPaths addObject:indexPath];
}
}

NSArray *selectedIndexPaths = self.tableView.indexPathsForSelectedRows;

for (NSIndexPath *indexPath in selectedIndexPaths) {
[allIndexPaths removeObject:indexPath];
}

NSArray *unselectedIndexPaths = [NSArray arrayWithArray:allIndexPaths];

编辑:根据 Rikkles建议

NSMutableArray *unselectedIndexPaths = [@[]mutableCopy];
NSArray *selectedIndexPaths = self.tableView.indexPathsForSelectedRows;
NSInteger nSections = [self.tableView numberOfSections];
for (int j=0; j<nSections; j++) {
NSInteger nRows = [self.tableView numberOfRowsInSection:j];
for (int i=0; i<nRows; i++) {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:j];
if (![selectedIndexPaths containsObject:indexPath]) {
[unselectedIndexPaths addObject:indexPath];
}
}
}

关于ios - 未选择的 UITableView 行列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15403342/

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