简体   繁体   English

如何自动滚动UITableView?

[英]How to auto-scroll UITableView?

I am trying to do something interesting. 我正在尝试做一些有趣的事情。

I am pulling some JSON data and populating cells in a UITableView. 我要提取一些JSON数据并在UITableView中填充单元格。 How can I make the UITableView scroll ever second or so? 如何使UITableView每秒滚动一次? I want to give the effect that as new data is coming in, the table is scrolling, so it is streaming. 我想给人的效果是,随着新数据的传入,表格正在滚动,因此它正在流式传输。

Any ideas? 有任何想法吗?

Yes, use scrollToRowAtIndexPath:atScrollPosition:animated: . 是的,请使用scrollToRowAtIndexPath:atScrollPosition:animated:。

You could also use UIScrollView's scrollRectToVisible:animated: if you want to have more finegrained control and can calculate exactly what your scroll position should be in pixels. 您还可以使用UIScrollView的scrollRectToVisible:animated:如果您希望拥有更细粒度的控件,并且可以精确计算滚动位置应以像素为单位。 (UITableView is subclass of UIScrollView.) (UITableView是UIScrollView的子类。)

But if you are just adding cells, sounds like you could also just use insertRowsAtIndexPaths:withRowAnimation: , this is also "interesting." 但是,如果您只是添加单元格,听起来您也可以只使用insertRowsAtIndexPaths:withRowAnimation:,这也是“有趣的”。

Just do this 做这个

[table reloadData];



NSIndexPath *myIP = [NSIndexPath indexPathForRow:[arrayIn count]-1 inSection:0] ;


  [table scrollToRowAtIndexPath:myIP atScrollPosition:NULL animated:YES];

in anywhere where arrayIn is your array by which your table populate. 在arrayIn是用来填充表的数组的任何位置。

you can use uitableviews scrollToRowAtIndexPath to do this....heres a link reference 您可以使用uitableviews scrollToRowAtIndexPath做到这一点....继承人的链接引用

You can call this method whenever as youd like to scroll your tableview 您可以随时滚动表视图来调用此方法

而且,您可以调用performSelector:withObject:afterDelay:来获得计时器效果-尽管如果您确实确实每秒都在提取数据,那么最好随手就去重载Data。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM