My, we do seem to be writing a lot about UITableView recently, don’t we? But this is a particularly good one — how to implement multiple-row selection and actions:
UITableViewdoes not support multiple selection. We will use the methodtableView:didSelectRowAtIndexPath:to detect touches in rows but the selected state will need to be stored separately (we cannot rely on theUITableView‘s selection).We will also need a background view for displaying the selection color and a
UIImageViewfor displaying the not-selected/selected indicator. Since theUIImageViewwill be hidden while not editing and the label for the row needs to move left or right when it is shown or hidden, we will also need to implement some form of layout for theUITableViewCell.Other required behaviors include switching the “Edit”/”Cancel” buttons between modes, showing/hiding the toolbar at the bottom and tracking the number of selected rows to display in the button in the toolbar…
Mighty handy stuff, that. Code can be downloaded here. And from quickly flipping around, looks like the entire CocoaWithLove blog this comes from is worth your perusal, there’s quite a number of nifty pieces of esoterica therein.
h/t: iPhoneKicks!
JAN