У меня есть настройка TableView с различными разделами и элементами в ней.
Когда я выбираю ячейку, изображение не отображается.
Однако он не просто делает это с одной ячейкой, он делает это с каждой восьмой в этом случае. В другом проекте это число было каждым десятым.
Кто-нибудь знает почему такое происходит и как это исправить?
import UIKit
struct Section {
let letter : String
let names : [String]
}
var sections = [Section]()
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var table: UITableView!
var data = ["Alb","bim","ck","Da","Esel","fried","fried","fried","fried","fried","fried","fried","fried","fried","fried","fried","fried","fried","fried","fried","fried","fried","spacko","yarr","mom","nun","loser","zebra","jao","ihr","peep","reee","vogel","xylo","uuuf","tiiii","qqqq","m","z","aw","bim","ce","did","Esel","fried","fried","fried","fried","fried","fried","fried","fried","fried","fried","fried","fried","fried","fried","fried","fried","fried","spacko","yarrack","mom","nun","loser","zebra","jao","ihr","peep","reee","vogel","xylo","uuuf","tiiii","qqqq","m","z"]
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return sections[section].names.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! TableViewCell
return cell
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return sections[section].letter
}
func sectionIndexTitles(for tableView: UITableView) -> [String]? {
return sections.map{$0.letter}
}
override func viewDidLoad() {
super.viewDidLoad()
table.rowHeight = 90.0
let groupedDictionary = Dictionary(grouping: data, by: {String($0.prefix(1))})
let keys = groupedDictionary.keys.sorted()
sections = keys.map{ Section(letter: $0, names: groupedDictionary[$0]!.sorted()) }
table.reloadData()
}
func numberOfSections(in tableView: UITableView) -> Int {
return sections.count
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cell = tableView.cellForRow(at: indexPath) as! TableViewCell
cell.checkmark.isHidden = !cell.checkmark.isHidden
}
}
import UIKit
class TableViewCell: UITableViewCell {
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
@IBOutlet weak var checkmark: UIImageView!
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}