UITableView didSelectRowAt is not called iOS 10, but works for 9.3.5

梦想的初衷 提交于 2019-12-06 07:56:53

问题


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


回答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.



来源:https://stackoverflow.com/questions/44447365/uitableview-didselectrowat-is-not-called-ios-10-but-works-for-9-3-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!