uitableview - In an iOS table view, how should a row be moved to a new section? -
uitableview - In an iOS table view, how should a row be moved to a new section? -
i have table view 2 rows in 1 section, i.e
--- row row b
if want animate row 1 new section, i.e. end result being:
--- row b --- row
how should achieved? have tried is:
[self.tableview beginupdates]; [self.tableview deleterowsatindexpaths:@[[nsindexpath indexpathforrow: 0 insection: 0]] withrowanimation:uitableviewrowanimationnone]; [self.tableview insertsections:[nsindexset indexsetwithindex: 1] withrowanimation:uitableviewrowanimationnone]; [self.tableview endupdates];
however, in ios 8 @ least, row animates out new section un-rendered (i.e. white, no bottom row border) until time after when triggers redraw , comes back.
[self.tableview beginupdates]; [self.tableview moverowatindexpath:[nsindexpath indexpathforrow:0 insection:0] toindexpath:[nsindexpath indexpathforrow:0 insection:1]]; [self.tableview endupdates];
which raises exception:
invalid update: invalid number of sections. number of sections contained in table view after update (2) must equal number of sections contained in table view before update (1), plus or minus number of sections inserted or deleted (0 inserted, 0 deleted).
and:
[self.tableview beginupdates]; [self.tableview insertsections:[nsindexset indexsetwithindex: 1] withrowanimation:uitableviewrowanimationnone]; [self.tableview moverowatindexpath:[nsindexpath indexpathforrow:0 insection:0] toindexpath:[nsindexpath indexpathforrow:0 insection:1]]; [self.tableview endupdates];
which raises exception:
cannot move row newly inserted section (1)
should not animate @ , reload whole table?
you'll need perform in 2 steps.
first you'll need add together section; need tell info source business relationship new section. simple illustration yours, can set variable:
- (nsinteger)numberofsectionsintableview:(uitableview *)tableview { if(hastwosections) homecoming 2; homecoming 1; }
then want trigger animation, call:
hastwosections = true; // needs set before endupdates [self.tableview beginupdates]; [self.tableview insertsections:[nsindexset indexsetwithindex: 1] withrowanimation:uitableviewrowanimationautomatic]; [self.tableview endupdates];
at point, tableview phone call info source methods update table based on changes.
once section has been added, can move row in update block:
[self.tableview beginupdates]; [self.tableview moverowatindexpath:[nsindexpath indexpathforrow:0 insection:0] toindexpath:[nsindexpath indexpathforrow:0 insection:1]]; [self.tableview endupdates];
obviously you'll need update numberofrowsinsection returns business relationship change.
although it's 2 steps, it's happening @ once.
ios uitableview
Comments
Post a Comment