ios – 使用UITableViewAutomaticDimension在顶部插入行时保持UITableView偏移

ios – 使用UITableViewAutomaticDimension在顶部插入行时保持UITableView偏移,第1张

概述我的应用程序中有一个带有Autolayout的UITableView. 按下LoadEarlier Button索引[0]后,我需要在TableView中插入一些行, 但我想留在我的TableView的最后一个位置.(像WhatsApp& …那样加载早期). 我的问题是在设置contentOffset之后我的TableVoew的位置不正确. 我检查这个链接,但这个问题不像我的问题,但我认为答案可以 我的应用程序中有一个带有autolayout的UItableVIEw.
按下LoadEarlIEr button索引[0]后,我需要在tableVIEw中插入一些行,
但我想留在我的tableVIEw的最后一个位置.(像WhatsApp& …那样加载早期).

我的问题是在设置contentOffset之后我的tableVoew的位置不正确.

我检查这个链接,但这个问题不像我的问题,但我认为答案可以帮助我们.
UITableViewAutomaticDimension – Cells move when table is reloaded
这个链接:
Keep uitableview static when inserting rows at the top

我这样做:

// in VIEwDIDLoadself.mytableVIEw.estimatedRowHeight = 100;self.mytableVIEw.rowHeight  = UItableVIEwautomaticDimension;//implemention of LoadEalIEr MethodCGfloat oldtableVIEwHeight = self.mytableVIEw.contentSize.height;for (int i = temp ; i < 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);

如果我从我的代表&删除automaticDimension ….它在静态的细胞高度上完美地工作,但是我需要automaticDimension来计算我的细胞的高度.

解决方法 更新

我找不到使用UItableVIEwautomaticDimension保持UItableVIEw偏移的解决方案.

我从heightForRowAtIndexPath&中删除了UItableVIEwautomaticDimension. estimateForRowAtIndexPath和保持UItableVIEw:

CGfloat oldtableVIEwHeight = self.tableVIEw.contentSize.height; // we keep current content offSet for revert to this position after Reload table// Update your Data[self.tableVIEw reloadData];CGfloat finalYPostioton = self.tableVIEw.contentSize.height - oldtableVIEwHeight - numberOfYourSection * sectionHeight;finalYPostioton = finalYPostioton - spaceFromtopCell; // we need this for showing a little of top cell from our index. spaceFromtopCell -->10[self.tableVIEw setContentOffset:CGPointMake(0,finalYPostioton)  animated:NO];
总结

以上是内存溢出为你收集整理的ios – 使用UITableViewAutomaticDimension在顶部插入行时保持UITableView偏移全部内容,希望文章能够帮你解决ios – 使用UITableViewAutomaticDimension在顶部插入行时保持UITableView偏移所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1004362.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存