在用户单击UITableViewCellAccessoryDetailDisclosureButton时显示选项,可以通过以下步骤实现:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.textLabel?.text = "选项\(indexPath.row)"
cell.accessoryType = .detailDisclosureButton
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
performSegue(withIdentifier: "showOptions", sender: indexPath)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let identifier = segue.identifier {
if identifier == "showOptions" {
if let destinationVC = segue.destination as? OptionsViewController, let indexPath = sender as? IndexPath {
destinationVC.indexPath = indexPath
}
}
}
}
在目标视图控制器中,根据indexPath加载相应的选项,并在视图加载时显示。
class OptionsViewController: UIViewController {
var indexPath: IndexPath?
override func viewDidLoad() {
super.viewDidLoad()
if let indexPath = indexPath {
// 加载相应的选项
// 显示选项
}
}
}
这样,当用户单击UITableViewCellAccessoryDetailDisclosureButton时,就会显示相应的选项。
领取专属 10元无门槛券
手把手带您无忧上云