- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
最近想根据indexPaths删除单元格,所以函数的入参是[IndexPath]
类型,需要根据把[IndexPath]拆分成几个数组indexPath.section
,有什么简单的方法吗?例如
indexPaths =
[IndexPath(row: 0, section: 1),
IndexPath(row: 1, section: 1),
IndexPath(row: 2, section: 1),
IndexPath(row: 2, section: 0)]
想把这个转换成
indexPath1 =
[IndexPath(row: 0, section: 1),
IndexPath(row: 1, section: 1),
IndexPath(row: 2, section: 1)]
indexPath0 =
[IndexPath(row: 2, section: 0)]
// maybe get a [Array]
[indexPath0, indexPath1]
最佳答案
一个可能的解决方案是首先构建一个字典,其中键是节号,值是该节中 IndexPath
的数组。
let indexPaths = [
IndexPath(row: 0, section: 1),
IndexPath(row: 1, section: 1),
IndexPath(row: 2, section: 1),
IndexPath(row: 2, section: 0),
]
let pathDict = Dictionary(grouping: indexPaths) { (path) in
return path.section
}
然后你可以将这个字典映射到路径数组的数组中。但首先按部分对这些数组进行排序。
let sectionPaths = pathDict.sorted { (arg0, arg1) -> Bool in
return arg0.key < arg1.key // sort by section
}.map { $0.value } // get just the arrays of IndexPath
print(sectionPaths)
输出:
[[[0, 2]], [[1, 0], [1, 1], [1, 2]]]
关于swift - 如何将 indexPath 数组拆分为单独的 indexPath 数组,每个数组的 indexPath 具有相同的 indexPath.section,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55877235/
最近想根据indexPaths删除单元格,所以函数的入参是[IndexPath]类型,需要根据把[IndexPath]拆分成几个数组indexPath.section,有什么简单的方法吗?例如 ind
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topi
我有一个 TableViewController,其中包含使用 CoreData 的数据条目列表。我还有带 TextView 的 ViewController。我已经完成了对项目的添加、保存和删除等操
我正在编写一个 UICollectionViewLayout 子类。 我知道 Collection View 有多少个部分...numberOfSections。 我知道每个部分有多少项目...num
这是我的 collectionViewCell 图像。 我在 tableViewCell 中有 collectionView 并且在 collectionViewCell 中有一个按钮,它完全符合我的
这个问题在这里已经有了答案: Passing data between view controllers (45 个答案) 关闭 3 年前。 我在 UIViewController 中定义它并尝试在
我在我正在开发的应用程序中的表格单元格上设置长按手势时遇到了一些问题。我已经尝试了三种不同的配置,但还没有一种能够成功运行。 场景 1) 我将 UILongPressGestureRecognizer
在我更新到 Xcode 7.2 后,弹出一个错误提示“下标的使用不明确”: func tableView(tableView: UITableView, cellForRowAtIndexPath i
我在 UITaleViewCell 中有一个 UIImageView,我向 UIImageView 添加了一个点击识别器。 - (IBAction)ui_tapped:(UITapGestureRec
我正在尝试追踪应用程序中的严重崩溃。 我有一些代码可以有效地做到这一点: if let indexPath = self.tableView.indexPath(for: myTableViewCel
我有一个 UITableView,一个自定义单元格的自定义类和我的 ViewController swift: private var model_firma = [Firme]() var firm
我有一个 Tableview,显示一个包含 7 行的部分,我想要做的是,当我按第 0 行时,我将其发送到另一个 View ,表中的所有信息都是通过使用修复的代码加载的,我的问题是如何在“prepare
我注意到要禁用表格单元格的突出显示功能,您可以使用以下方法: override func tableView(tableView: UITableView, didSelectRowAtIndexPa
这个问题在这里已经有了答案: Issue Detecting Button cellForRowAt (3 个答案) 关闭 2 年前。 使用此代码,我只获得具有 indexpath.row 如何从中
我正在开发一个待办事项应用程序。在我的应用程序中,我按下复选框按钮来删除一行。我编写这段代码是为了将 indexPath.row 传递到我的复选框按钮中: cell.checkbox.tag = in
我有一个像这样的UIViewController: class ViewController { override func viewDidLoad() { super.vie
不知道你有没有遇到过这种情况,我用的是该函数 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPa
UITableViewController 的 numberOfSection 和 numberOfRowsInSection 被调用,但 cellForRow 没有。可能是什么原因 ?下面是 tab
我是 Stack Overflow 的新手,所以请保持温柔! 我正在设计一个应用程序,它从 firebase 检索对象并在 firebase 中显示它们。 我在这里配置firebase: func a
我手头有一个非常原始的问题,那就是当我将点击手势识别器添加到我的自定义单元格时,我无法调用 didSelectRowAt 方法。 我的代码如下: import UIKit class Language
我是一名优秀的程序员,十分优秀!