JRG-Developer / AutoLayoutCells

AutoLayoutCells makes working with dynamic table view cells easy.
MIT License
26 stars 4 forks source link

`tableView: didSelectRowAtIndexPath:` not being forwarded from `ALTableViewCellFactory` #8

Closed AnthonyMDev closed 9 years ago

AnthonyMDev commented 9 years ago

I'm not sure if I'm doing something wrong, but I cannot get tableViewDidSelectRowAtIndexPath to be forwarded from the factory to my view controller.

AnthonyMDev commented 9 years ago

I figured out what the problem was here.

respondsToSelector is being called for each of the delegate methods on the ALTableViewCellFactory right after initialization. At this point, the delegate is nil. Once the delegate is set, it is too late, and none of these selectors will be forwarded, as the ALTableViewCellFactory has already said that it does not respond to the selectors.

By changing the ALTableViewCellFactory so that the delegate is set in the initalization of the factory, the problem is solved. This might cause some odd behavior if the delegate if the cell factory is ever changed though.

Do you see any time where the delegate should be changed? I can't think of a use case.

I propose that the delegate property be converted into a private or protected property that is set on initialization and then should not be changed.

Any comments/suggestions?

AnthonyMDev commented 9 years ago

Upon further review, the respondsToSelector methods are being called when the delegate and dataSource properties are set on the tableView

I've solved this problem in #9 by creating a custom setter for the delegate property on the ALTableViewCellFactory. This setter resets the delegate and dataSource for the tableView, so the respondsToSelector calls are made again.

When the delegate and dataSource are set to the same object that they already are, the respondsToSelector methods are not called, so the properties must be set to nil and then reset.

This solves the problem while still allowing the ALTableViewCellFactory delegate to be changed.

This is a pretty huge bug, and makes the library un-usable by me. I'm hoping that this can be pulled in soon.

Thanks!

JRG-Developer commented 9 years ago

Ok, I've been able to reproduce this problem in the demo. I should have something soon.

JRG-Developer commented 9 years ago

Done. Added to CocoaPods as version 0.6.1.