objective c - What is the purpose of the delegate method 'canMoveRowAtIndexPath'? -
i'm working on ui component right now, , behaves uitableview, i'm heavily modeling delegate , data source protocols after of uitableview. however, noticed 1 method don't quite understand- 'canmoverowatindexpath'.
this allows delegate specify whether wants given cell 'movable'. however, wouldn't dropping movable cell higher index immovable cell (i.e. 'above' in table) cause indirectly move anyway? (since every cell below moved 1 pushed down 1 row).
so basically, question point of method? can provide example use-case it? because i'm debating whether should bother including in component or not.
if anything, think perhaps more useful delegate method such 'canmoverowinsection', allow specify whether rows in given section can moved. allow disable reordering of particular section, , moving other rows outside of section not affect ordering of rows inside it.
i know apple engineers provided method reason, can't see reason might be.
thanks insight!
canmoverowatindexpath tells uitableview if table in editing mode, cells (or cell, if choose specifically) can moved , down.
it's developer handle other side of move.
for instance, have array (nsmutablearray exact) of "a", "b", "c" , want rearrange array "b", "c", "a". need make change in array based on location of cell being moved , save array.
example
-(bool)tableview:(uitableview *)tableview canmoverowatindexpath:(nsindexpath *)indexpath { return yes; } - (void)tableview:(uitableview *)tableview moverowatindexpath:(nsindexpath *)fromindexpath toindexpath:(nsindexpath *)toindexpath { id objecttomove = [[array objectatindex:fromindexpath.row] retain]; [array removeobjectatindex:fromindexpath.row]; [array insertobject:objecttomove atindex:toindexpath.row]; [objecttomove release]; } section example
this example says if table section 0, no cells can move. other section (say have 3), cells in section 1 , 2 can move. still need handle array accordingly.
-(bool)tableview:(uitableview *)tableview canmoverowatindexpath:(nsindexpath *)indexpath { if ( indexpath.section == 0 ) return no; return yes; }
Comments
Post a Comment