私はSwiftを初めて使用しています。私はテーブルビューで複数の行選択を無効にしたいと考えています。私はアプローチの異なるタイプを実装しようとし、私の最終的なコードブロックは動作していません、以下です。 ご協力いただきありがとうございます。SwiftのTableviewで複数行選択を無効にする
override func viewDidLoad() {
super.viewDidLoad()
companyTableView.allowsMultipleSelection = false
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if let cell = tableView.cellForRow(at: indexPath) {
cell.accessoryType = .checkmark;
}
tableView.deselectRow(at: indexPath, animated: true)
if let cell = tableView.cellForRow(at: indexPath) {
cell.accessoryType = .checkmark
}
tableView.deselectRow(at: indexPath, animated: true)
if let cell = tableView.cellForRow(at: indexPath) {
if selectedCells.contains(indexPath.row) {
selectedCells.remove(indexPath.row)
cell.accessoryType = .none
} else {
selectedCells.insert(indexPath.row)
cell.accessoryType = .checkmark
}
}
}
'allowsMultipleSelection = false'をが正常に動作しています。 –
デフォルトでは、単一選択はストーリーボードでのみ選択されています。ストーリーボード - >あなたのテーブルビューを選択し、属性インスペクタの下に、選択肢なし、単一選択、複数選択があります。実行時に変更したくない場合は、ストーリーボードから設定することができます。 'allowsMultipleSelection'のデフォルト値もfalseです。 – Priyal
'cellForRowAtindexPath'コードを表示します。 –