The Hit List Diary #19.1 – Blocks as Cell Actions

Following my exploration of delegation and the responder chain for sending actions from within cells, Daniel Tull mentioned that he prefers using blocks. Consider a setup like this:

The cell holds onto an arbitrary block, which it executes when the checkbox is pressed.

It’s easy for the block to know exactly which cell the action is coming from, and the corresponding model object, by capturing that information as part of its scope. You do need to watch out for retain cycles though; happily the compiler tends to be pretty good at spotting that.

For some reason I can’t put my finger on though, this setup does still make me slightly uncomfortable. Seems perfectly valid though, so who knows!

© Mike Abdullah 2007-2015