Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
878 views
in Technique[技术] by (71.8m points)

swift - IBAction inside UITableViewCell not called in iOS 9

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

Under iOS 8 everything works as expected. If the user taps one of the buttons, the appropriate IBAction is called. If the user taps anywhere else on the cell, the UITableView didSelectRowAtIndexPath is called.

Under iOS 9, my IBAction methods are never called. The UITableView didSelectRowAtIndexPath is always fired regardless of where the user taps in the cell (button or not).

The project is compiled under Xcode 6 / Swift 1.2.

I found this post on an Apple forum w/ no solution. They seem to have the same issue.

https://forums.developer.apple.com/thread/16179

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...