I have an UIScrollView that is a rapidly updating Twitter stream following a certain search term. A large number of tweets are handled per second. I’d like the user to be able to touch anywhere on the table view and have it stop scrolling as new tweets are added so that the user can stop and read an individual tweet.
Currently, I’m adding tweets like so:
[self.tweets insertObject:model atIndex:0];
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:0 inSection:0]] withRowAnimation:UITableViewRowAnimationTop];
When a tweet is added, the scroll view’s position is locked and because of this the entire view shifts down to accommodate the tweet. At such a rapid pace, this makes the tweets on the screen zoom by at an illegible pace. Ideally, I’d like to make it so that if there is contact with the TableView (accomplished by a UIButton covering it) then the scroll positioning becomes locked to that row in the view. What’s the best way to approach this?
Every time you add a tweet make an allowance for its height by altering the scroll position of the table view. To do this use
setContentOffset:animated:. UseNOfor theanimatedparameter to make the change instant and pass aCGPointthat is relevant to the tweet’s height. So if the tweet has a height of 50 then do something like:This will scroll the table view up by 50 meaning that the user will have to scroll to view the tweet that has just been added.