I'm currently implementing swiping functionality for my custom table view cell and I came across the problem. I want my UIScrollView embedded in cell to reset its contentOffset on table view scroll. The only possible solution I came up with at the moment is to retrieve visibleCells from table view on each scrollViewDidScroll call, cast it to my type and then apply modifications to each of them but I think it might be quite costly and will probably affect performance on older devices. Is there any better way to do that? Thanks in advance!
You could use NotificationCenter.
Post a notification to NotificationCenter within ´scrollViewDidScroll´
within your cell’s subclass, use ´NotificationCenter.default.addObderver() and reset the contentOffset whenever this notification has been received.
Related
I have a UITableView in my application. When the table is scrolled almost to the end, I download more data and reload the table.
If the tableView was scrolling, at the time I call [tableView reloadData]; scrolling stops. How can I achieve effect of not stopping the scroll meanwhile reloadData? I think I need to somehow save scrolling speed and then restore it, but how to do this?
P.D. I really searched this question before asking.
I thing, this method (insertRowsAtIndexPaths:withRowAnimation:) is the key.
There is a use case and a nice tip described on SO: the use case and the tip.
Since UITableView is subclass of UIScrollView, you can use UIScrollViewDelegate's scrollViewWillEndDragging:withVelocity:targetContentOffset:
method to determine how far it is supposed to scroll and then after table reload call setContentOffset:animated: with that target offset (or beginning/ending of tableview if it becomes smaller) to simulate continued scrolling
EDIT: since your targetContentOffset is probably going to be CGRectZero, you will have to recalculate it somehow using velocity from the same method
if i am not wrong you are looking for a function call Lazy load. I can recommend you to search SVPullToRefresh
here!
I'd like to implement a feed in iOS 7 that is only pulling new data if it appears the user has a chance of viewing it. I know UITableView is a subclass of UIScrollView that does this well, but I can't get the cells to behave the way I'd like - I'd like it to look similar to facebook or twitter's newsfeed where you can reload by pulling down and load more by hitting the bottom.
I've seen other questions such as this but I'm looking for vertical scrolling only, with absolutely no horizontal movement. I'd like to use a method calling (for example) nextTenPostsFromIndex: that instantiates from zero, and applies to whatever index was the last on the screen if hitting the bottom.
My question: Is the best way to go about this to create a UIScrollView, place a subview inside of it, and programmatically space them on the available scrollview space, and apply the same drawing methods again with repopulated data if nextTenPostsFromIndex is called or checkForNewPosts (if pulling down from the top)? Would this be a reasonable way to implement Facebook's iOS7 newsfeed, or others like it?
Short answer: No. You really ought to use UITableView for things like this. You can use a custom cell or whatever you want. If it helps you, also know that since UITableView is a subclass of UIScrollView, you can do anything you would normally do with a scrollview, including assigning a delegate which acts based on the current position when scrolling.
I am using a UICollectionView in my app with gesture recognizers on the individual cells which allow the user to "slide open" the cell to reveal more data underneath.
The problem is, I am reloading the data in the CollectionView very often; as the app receives updates once every 3 seconds or so. This results in unwanted behavior with the collectionview cells being reused while a cell is in the process of being slid.
The user will start to slide a cell, the app will receive an update, reloadData, and a different cell will start receiving the gesture instead, and begin sliding.
I have tried disabling the app's updates while the slide is occurring, but that caused other complications within the app, so I am wondering if there is a way to disable the cell reuse, (I will only have 20 cells max, so I don't think there would be a large drop in performance).
Thank you!
Why don't you use a flag like needsReload and set it, if new data is available. After a slide you check for that flag and reload the collectionView, if needed? Is this not working?
If you don't want cell reusing, just use a default scrollView and put all your views in it!?
Disabling reuse is simple. Just don't use the dequeueReusableCell method.
Instead just alloc, init your cells. I would be careful of the performance and memory implications of doing so though...
I am trying to support infinite scroll in tableview.
I know tableview lets scroll infinitely, but my case is different.
Initially, I will load 30 items in my tableview as the user scrolls down close to 30th element, I will make a http request to get next 30 items so its not like I am loading 60 items at once.
My way about going to do this is when my table is initally filled with 30 items, once the footerview is seen, then I will request the next 30 items.
My question is how to detect footerview is seen? Is there something like 'will appear' for just footerview?
Let me know if there is other better way of completing my scenario above
Thanks!!
A UITableView is a subclass of UIScrollView, and UITableViewDelegate conforms to UIScrollViewDelegate.
So you can set yourself as the tableViewDelegate and implement scrollViewDidScroll:. You can then either check the scrollView.contentOffset yourself, or call [myTableView visibleCells]. I am sure there are various other methods as well.
The behavior you are trying to implement is known as pull-to-refresh.
There are several implementation of it already available, e.g.:
https://github.com/leah/PullToRefresh
https://github.com/enormego/EGOTableViewPullRefresh
Give it a try, or read the code the learn the details. If you are curious, the way the trick is done is by implementing the delegate methods for the scroll view and checking the value of scrollView.contentOffset.y.
I'm stuck with the problem that I want to know in my UITableView if a specific UITableViewCell, let's say the first, is still visible or already off the visible area.
I would also be ok to know if the cell of interest is now beeing reused at an other indexPath of the table.
One of my - later and frustrated approaches - was to have a thread that knows the first cell object and frequently pings it to check if a value I did set in the cell changed. Obviously a not so good solution.
Andy ideas how to do this right?
Remember that UITableView is UIScrollView subclass and its delegate also confirms to UIScrollViewDelegate protocol as well.
So in your table delegate you can implement scrollViewDidScroll: method and check contentOffset - if it's more then first cell height then first cell is not visible. You can also get the array off all currently visible cells using -visibleCells method, but I think knowing contentOffset should be enough.