ios - Keep UITableView offset when inserting rows at the top with UITableViewAutomaticDimension -
i have uitableview
autolayout
in app. need insert rows tableview after press loadearlier
button index[0],
want stay on last position of tableview.(load earlier whatsapp & ...).
my problem after setting contentoffset
posion of tablevoew isn't correct.
i check link problem isn't problem think answer us. uitableviewautomaticdimension - cells move when table reloaded , link : keep uitableview static when inserting rows @ top
i :
// in viewdidload self.mytableview.estimatedrowheight = 100; self.mytableview.rowheight = uitableviewautomaticdimension; //implemention of loadealier method cgfloat oldtableviewheight = self.mytableview.contentsize.height; (int = temp ; < temp +26; i++) { myobject * tempobject = [[myobject alloc]init]; tempobject.name = [nsstring stringwithformat:@"obj : %d",i]; tempobject.uid = [[nsuuid uuid]uuidstring]; [_dataarray insertobject:tempobject atindex:0]; } [self.mytableview reloaddata]; cgfloat newtableviewheight = self.mytableview.contentsize.height; self.mytableview.contentoffset = cgpointmake(0, self.mytableview.contentsize.height - oldtableviewheight);
if remove automaticdimension delegate & .... it's work on static height of cell ,but need automaticdimension calculate height of cell.
update
i can't find solution keep uitableview
offset uitableviewautomaticdimension
.
i have removed uitableviewautomaticdimension
heightforrowatindexpath
& estimateforrowatindexpath
, keep uitableview
:
cgfloat oldtableviewheight = self.tableview.contentsize.height; // keep current content offset revert position after reload table // update data [self.tableview reloaddata]; cgfloat finalypostioton = self.tableview.contentsize.height - oldtableviewheight - numberofyoursection * sectionheight; finalypostioton = finalypostioton - spacefromtopcell; // need showing little of top cell our index. spacefromtopcell -->10 [self.tableview setcontentoffset:cgpointmake(0,finalypostioton) animated:no];
Comments
Post a Comment