【发布时间】:2019-09-07 01:42:23
【问题描述】:
我有这个表格视图,它通过核心数据填充。一切看起来都很好,即使在滚动时,直到我按住任何一行 - 然后该行就会像下面的第二张图片一样扭曲。
(来源:staticflickr.com)
(来源:staticflickr.com)
这是显示表格视图的代码
override func viewDidLoad() {
super.viewDidLoad()
animateBackground(colors)
tableView.delegate = self
tableView.dataSource = self
tableView.fetchData(fetchedResultsController as! NSFetchedResultsController<NSFetchRequestResult>)
self.tableView.tableFooterView = UIView(frame: .zero)
}
func numberOfSections(in tableView: UITableView) -> Int {
guard fetchedResultsController.sections?.count != nil else { return 0 }
return fetchedResultsController.sections!.count
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
guard fetchedResultsController.sections != nil else { return 0 }
let data = fetchedResultsController.sections![section]
return data.numberOfObjects
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "SkillCell", for: indexPath) as! SkillCell
configureCell(cell: cell, indexPath: indexPath as NSIndexPath)
return cell
}
func configureCell(cell: SkillCell, indexPath: NSIndexPath) {
let skill = fetchedResultsController.object(at: indexPath as IndexPath)
cell.skill = skill
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { }
}
从上面的代码来看,一切看起来都很正常,但是却出现了这种失真。请帮我看看为什么以及如何阻止它发生。
【问题讨论】:
-
它没有扭曲,当你点击它时单元格会突出显示。
-
将 Storyboard 中的 TableViewCell 属性 SelectionStyle 更改为无。