我正在尝试在我的应用程序中添加一项功能,以便一次将多个成员添加到一个操作中。成员列在 tableView
中,用户可以使用 .allowsMultipleSelection = true
函数一次选择多行。我得到了以下代码,但这不起作用。我认为我的想法会奏效,但不会像我在代码中那样:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
guard let destination = segue.destination as? AddMultipleMemberTransactionViewController,
let selectedRows = multipleMemberTableView.indexPathsForSelectedRows else {
return
}
destination.members = members[selectedRows]
}
这里有人知道我该如何解决这个问题,因为有一个错误:
Cannot subscript a value of type '[Member?]' with an index of type '[IndexPath]'
我在应用程序中拥有相同的功能,但仅适用于一名成员(member)。我在 indexPathForSelectedRow
之后的 let selectedRows
行中有一个 .row。 indexPathsForSelectedRows
是否有类似的功能?
或者这是错误的方法吗?
最佳答案
你需要
destination.members = selectedRows.map{ members[$0.row] }
关于ios - 如何将 tableView 的多行传输到另一个 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51730140/