tolkienfan2
tolkienfan2

Reputation: 151

Weird display behaviour when selecting tableview row

I have this table view, that populates through Core Data. Everything looks fine, even when scrolling, until I press and hold any row - then that row distorts like in the second image below. normal view
(source: staticflickr.com)

weird distortion
(source: staticflickr.com)

Here's the code to display the tableview

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) { }

}

From the code above, everything looks normal, yet this distortion occurs. Please help me to see why and how to stop it happening.

Upvotes: 2

Views: 58

Answers (2)

Haya Hashmat
Haya Hashmat

Reputation: 137

yes you should set tableView selection style to none. 1.Select the tableview in storyboard in the right panel set selection style to none. or 2.in your tableview cellforrow method set

tableView.selectionstyle = none 

Upvotes: 0

Muhammed G&#252;l
Muhammed G&#252;l

Reputation: 875

As the comment suggests, it's just a visual effect called selectionStyle of your UITableViewCell. Inside your cellForRowAt indexPath method, you can disable it like:

 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "myCell") as! MyCell
    cell.selectionStyle = .none // this removes the effect.
    return cell
}

Upvotes: 2

Related Questions