3

There are lots of questions regarding this problem, but the answers I have found so far are not applicable. In this case, the table works correctly in iOS 9.3.5, but not for iOS 10 (or 10.3.1)

I have ruled out:

  • Not setting up the delegate properly. The delegate performs 3 functions, didSelectRowAt, heightForRowAt, and editActionsForRowAt. The latter is the right-to-left swipe which gives the option to perform the exact same functionality as selecting the row.. These three functions work correctly on v9.3.5 (as tested via simulator and and older iPad I test with.) When I use v10 via the simulator or my iPhone SE, the heightForRowAt, and editActionsForRowAt work but not the didSelectRowAt (and for that matter - I tried willSelectRowAt. It also did not work for v10.)
  • Any typographical error (because it works for 9.3.5)

I have not been able to find anything about a Swift change regarding tableView(:didSelectRowAt) from iOS 9 to iOS 10.

Background

I have a view controller with a corresponding xib ("DetailVC"). This xib has a label then a tableview underneath the label. The table's cell is another xib.

The view controller presented via

let uomVC = DetailVC()
self.navigationController?.pushViewController(uomVC, animated: true)

Then within DetailVC, I use a NSFetchedDataController and connect it to tableview via the tableView Data Source delegate. (Core data loads and displays great.)

Code (I'll post additional code as needed/ requested - Swift 3)

viewDidLoad() - partial

let nib: String = "DetailCell"
let reuseID: String = "detailCell"
tableView.register(UINib.init(nibName: nib, bundle: nil), forCellReuseIdentifier: reuseID)

tableView(:cellForRowAt)

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: reuseID) as! IngredientDetailCell
    cell.present(ingredient: _fetchedResultsController.object(at: indexPath))
    cell.isUserInteractionEnabled = true // Added later as a guess per SO suggestions
    return cell
}

For arguments sake - this won't print

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {      
    print("Selected a row")
    // delegate?.selectedIngredient(_fetchedResultsController.object(at: indexPath))
    // self.navigationController?.popViewController(animated: true)
}

View

tableViewCell

LinusGeffarth
  • 27,197
  • 29
  • 120
  • 174
AgRizzo
  • 5,261
  • 1
  • 13
  • 28
  • what are the contents of the cell? I mean since it's a custom cell, what is the view hierarchy of `cell.contentView`? – Malik Jun 09 '17 at 00:40
  • @Malik - There's a pair of labels within a horizontal stack – AgRizzo Jun 09 '17 at 01:08
  • Make sure you're including your UITableViewDelegate and then self.tableView.delegate = self self.tableView.dataSource = self in viewDidLoad – webjunkie Jun 09 '17 at 01:44
  • Make sure you are not using any gesture. If you are using any gesture please just remove it and try didselectat method – Jitendra Modi Jun 09 '17 at 04:39
  • Looks like an interesting case. Will have to look at the class where you are using the tableView and possibly the tableView attributes in storyboard. – Malik Jun 09 '17 at 04:46
  • Just to make it clear is it exactly the same code being run on iOS 9 and iOS 10? – Upholder Of Truth Jun 09 '17 at 07:17
  • Does `tableView` recognises other touches on iOS 10? Do other delegate methods get called? – kelin Jun 09 '17 at 11:49

1 Answers1

1

For completeness in case anyone has this strange situation.

The problem was my UITableViewCell xib. I must have originally designed it as a UIView, then added the UITableViewCell. The hierarchy should begin with the UITableViewCell. I moved the UITableViewCell out from underneath the view (circled in red), deleted the view and re-connected the IBOutlets. It's just strange that it worked with iOS 9.3.5.

enter image description here

AgRizzo
  • 5,261
  • 1
  • 13
  • 28