本文介绍了如何在加载视图或重新加载 tableview 时在 UITableview 上显示最后添加的单元格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个聊天应用程序,我正在使用 UITable 视图来显示来自用户的回复和响应.在这种情况下,经过一段时间后,我将重新加载我的 tableview 以获取新数据从服务器.但问题是,在向表格视图添加新内容后,它将位于表格视图的底部,我必须滚动表格视图才能看到该内容.或者在其他情况下,每当我重新加载表格时,它将显示其第一个单元格看法.现在我的问题是是否可以在视图加载或重新加载表格视图后加载 UITableview 的最后一个单元格?"

all I am doing one chat application, i which i am using UITable view to display reply and response from user.in this case after some interval of time i am reloading my tableview to fetch new data from server. But the problem is that after adding new content to table view it will go at the bottom of table view and i have to scroll table view to see that one.or in other case whenever i am reloading my table it will show its first cell on view. Now my question is "is it possible to load last cell of UITableview after view gets load or reload table view?"

在搜索中我找到了这一行,但它给了我错误

on search I find this line but it give me error

[sTableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:sender.tag inSection:0]] withRowAnimation:UITableViewRowAnimationNone]; 

这一行中的 sender.tag 是什么?//使用未声明的标识符发送者

what is sender.tag in this line? // use of undeclared identifier sender

这条线运行良好,但滚动了我不想要的页面

This line working well but scrolling the page which i dont want

[table_readText scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES ];

非常欢迎任何想法或建议.

Any idea or suggestion would be highly welcome.

提前致谢..

推荐答案

您也可以查看滚动视图的 setContentOffset:animated: 方法.

You can also look at the scroll view's setContentOffset:animated: method.

顶部意味着,

[self.tableView setContentOffset:CGPointZero animated:YES];

底部是,

CGFloat height = self.tableView.contentSize.height - self.tableView.bounds.size.height;
[self.tableView setContentOffset:CGPointMake(0, height) animated:YES];

第二个选项:

scrollToRowAtIndexPath:atScrollPosition:animated:

滚动接收器,直到由索引路径标识的一行位于屏幕上的特定位置.

Scrolls the receiver until a row identified by index path is at a particular location on the screen.

- (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated

这篇关于如何在加载视图或重新加载 tableview 时在 UITableview 上显示最后添加的单元格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 13:35