答案 0 :(得分:6)
你可以试试这个。这个解决方案非常适合我。试一试也许为别人工作......
夫特-4
csv.reader()
答案 1 :(得分:4)
也许您可以实现表格视图的委托方法:
tableView(_:shouldHighlightRowAtIndexPath:)
和
tableView(_:didSelectRowAtIndexPath:)
...并确定(来自indexPath.row
和indexPath.section
)相关部分是否支持单/多选(这取决于您的数据模型的自定义逻辑-eg:&# 34;部分0
支持多选,但部分1
不支持#34;),如果它只支持单选,请检查是否已选择行(通过访问tableView.indexPathsForSelectedRows
) 。
如果已经有选定的行,您可以:
false
和tableView(_:shouldHighlightRowAtIndexPath:)
return
执行任何操作(仅tableView(_:didSelectRowAtIndexPath:)
)(我不确定当您从false
返回shouldHighlight...
时是否实际调用此方法,所以也许检查一下。)。答案 2 :(得分:2)
这很容易通过两行来实现,如下所示:(快速4)
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if sectionAllowsMultipleSelection {
if let indexPathsInSection = tableView.indexPathsForSelectedRows?.filter ({ $0.section == indexPath.section && $0.row != indexPath.row }) {
for selectedPath in indexPathsInSection {
tableView.deselectRow(at: selectedPath, animated: false)
}
}
}
}
答案 3 :(得分:0)
如果您希望第2部分中的选定行成为新选定的行,则这可能对您有用。另外,请使用@ NicolasMiari的回答。
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if indexPath.section == 1 {
for i in 0..tableView.numberOfRowsInSection(indexPath.section) - 1 {
let cell: UITableViewCell = tableView.cellForRowAtIndexPath(NSIndexPath(forRow: i, inSection: indexPath.section))!
if (i == indexPath.row) {
cell.accessoryType = .Checkmark
cell.selected = false
}
else {
cell.accessoryType = .None
}
}
}
else {
//Do whatever for the first section
}
}
不是很优雅,但希望它会给你一个想法。