【发布时间】:2017-07-06 11:32:06
【问题描述】:
我有一个包含不同部分的表格视图,我需要能够从不同部分中进行多选,但每个部分中的行应该能够明智地选择互斥。例如:在下面的屏幕截图中,我应该能够从披萨中选择玛格丽塔或烧烤鸡,对于深盘披萨也是如此,但我应该能够在披萨部分和深盘披萨之间进行多选
下面是我目前的代码,我想知道解决这个问题的最佳方法是什么。
let section = ["Pizza", "Deep dish pizza"]
let items = [["Margarita", "BBQ Chicken"], ["Sausage", "meat lovers"]]
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return self.section[section]
}
override func numberOfSections(in tableView: UITableView) -> Int {
return section.count
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return items[section].count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "tableCell", for: indexPath)
// Configure the cell...
cell.textLabel?.text = items[indexPath.section][indexPath.row]
return cell
}
【问题讨论】:
-
你确定 tableview 是合适的选择吗? picker 听起来是个更好的选择
标签: ios uitableview swift3 multi-select xcode8