나는 TableViewController에 정적 테이블이 있습니다. 행을 선택할 때마다 셀 전체가 회색으로 채워집니다. 내가 탭하는 모든 행에 대해이 작업을 수행합니다. 내가 사용하는 경우 :선택 세포가 제대로
cell.selectionStyle = .none에게
을이 셀 대신 흰색 채우기 할 것입니다.
의 tableview 속성 관리자 :
TableViewCell 검사기 특성 :
TableViewController :
import UIKit
class OptionTableViewController: UITableViewController {
@IBOutlet var optionsTable: UITableView!
let defaults = UserDefaults.standard
let numberOfRows = [7,2]
let cellIdentifier = "OptionCells"
override func viewDidLoad() {
super.viewDidLoad()
optionsTable.register(UITableViewCell.self, forCellReuseIdentifier: cellIdentifier)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that con be recreated.
}
override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 2
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
var rows = 0
if(section < numberOfRows.count){
rows = numberOfRows[section]
}
return rows
}
override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
cell.selectionStyle = .none
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath)
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath)
cell.textLabel?.text = optionSelections[indexPath.row]
return cell
}
}
나는 내가 제대로 모든 설정을 믿습니다. 왜 내가 세포를 두 드릴 때 세포를 채우는가?
업데이트 : 현재 가지고있는 것을 보여주기 위해 코드가 업데이트되었습니다.
업데이트 2 : 다른 모든 셀을 탭하기 전후의 테이블 모양을 보여주기 위해 두 장의 그림을 포함했습니다.
업데이트 3 : 셀을 dequeuing하여 액세서리 유형을 체크 표시로 변경했습니다.
; 셀이 재사용되고 셀 중 일부가 선택되어 (아마도) 셀렉션의 selectionStyle이 이미 '있기 때문에 일관성이없는 이유는 무엇입니까?없음 '을 표시합니다. – holex
@ 홀렉스 그게 실수 였어.하지만 selectionStyle을 올바른 위치에 놓았을 때도 여전히 셀을 회색으로 채 웁니다. – user1715916
didSelectRowAt 메서드를 제거해보십시오. 셀을 큐에서 꺼내므로 안됩니다. 나는이 세포들이 "올바른"세포의 꼭대기에 쌓여 있다고 의심한다. 보기 디버거를 사용하여 확인하십시오. – pbasdf