Sheehan Alam
Sheehan Alam

Reputation: 60879

How to auto-scroll UITableView?

I am trying to do something interesting.

I am pulling some JSON data and populating cells in a UITableView. How can I make the UITableView scroll ever second or so? I want to give the effect that as new data is coming in, the table is scrolling, so it is streaming.

Any ideas?

Upvotes: 1

Views: 6386

Answers (4)

Nagendra Tripathi
Nagendra Tripathi

Reputation: 923

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.

Upvotes: 1

Jaanus
Jaanus

Reputation: 17866

Yes, use 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. (UITableView is subclass of UIScrollView.)

But if you are just adding cells, sounds like you could also just use insertRowsAtIndexPaths:withRowAnimation:, this is also "interesting."

Upvotes: 4

Paul Lynch
Paul Lynch

Reputation: 19789

And you can call performSelector:withObject:afterDelay: for the timer effect - although if you are really pulling in data every second, it's best to just reloadData as you go.

Upvotes: 0

Daniel
Daniel

Reputation: 22395

you can use uitableviews scrollToRowAtIndexPath to do this....heres a link reference

You can call this method whenever as youd like to scroll your tableview

Upvotes: 0

Related Questions