IBAction inside UITableViewCell not called in iOS 9

后端 未结 2 1788
滥情空心
滥情空心 2020-12-14 11:07

I have a custom UITableViewCell subclass which contains a few IBAction methods wired up from a nib.

Under iOS 8 everything works as expecte

相关标签:
2条回答
  • 2020-12-14 12:00

    I figured out the solution, hopefully this answer will save someone else the time.

    I inherited this code base and it had some issues. The UITableViewCell's that were not working under iOS 9 were not using UITableViewCell nibs w/ a ContentView. Instead, someone had created a UIView nib and then pointed it to a custom UITableViewCell subclass. The nibs did not have a ContentView and apparently iOS 9 is a little more picky about that. This implementation worked fine under iOS 8 and there were no compiler or runtime errors or warnings.

    The solution was to create a new UITableViewCell subclass and let Xcode auto create the nib for it. Then I copied over all of the UI and code from the old nib and pasted it into the ContentView of the new nib. I then had to fix up the constraints and rewire the connections to the custom subclass.

    0 讨论(0)
  • 2020-12-14 12:10

    Just add this line in tableView cellForRowAtIndexPath method

    cell.contentView.userInteractionEnabled = false;
    return cell;
    

    but this is not a proper solution.

    iOS 9, puts a content view to a tableViewCell, even though you use a custom cell/xib. The content view being added after the custom cell, it was on top of it.

    To solve this properly just replace custom cell/xib's view with UITableviewCell from object library [from where you usually drag&drop UIButton, UILabel, etc...];

    0 讨论(0)
提交回复
热议问题