在didselect时将数据附加到每个部分

时间:2018-09-07 07:38:15

标签: ios

这是我的代码:-

 let selectedIndexPathAtCurrentSection = questionViewModel.selectedIndexPaths.filter({ $0.section == indexPath.section})

            print(selectedIndexPathAtCurrentSection)

                for indexPath in selectedIndexPathAtCurrentSection {
                    print(indexPath)

                    tableview.deselectRow(at: indexPath, animated: true)
                    if let indexOf = questionViewModel.selectedIndexPaths.index(of: indexPath) {
                        questionViewModel.selectedIndexPaths.remove(at: indexOf)
                    }
                }
                questionViewModel.selectedIndexPaths.append(indexPath)

                print(questionViewModel.selectedIndexPaths)
                print(indexPath)

因此,根据

何时选择该行。输出显示为:-

[[0,0]]

这是第一部分。假设我选择第二个索引,然后输出如下

[[0,1]]

此输出将显示在questionViewModel.selectedIndexPaths

当我选择第二部分选项时,questionViewModel.selectedIndexPaths的输出将显示如下。

[[1,0]]

但是在选择每个部分时,我需要如下补充。

[[0,1],[1,0]]

如何实施?

0 个答案:

没有答案