Is there quick way to know what cell is out of device screen in UITableView? - objective-c

I have tableView with a lot of cells. I need to remove cells, which user passes while scrolling the tableView.
cellForRowAtIndexPath is called when user scroll to this cell to perform its content and the question is there similar method to know what cells are out of the screen while scrolling?

Take a look at UITableView's visibleCells method. It'll tell which ones are visible. Then I'm assuming you know how many total cells there are and you can do the logic to work out which ones are not visible.

Related

Select CollectionViewCell when scrolled into view

I have a collection view that is 100 points wide with a number of cells that are each also 100 points wide. I've got it setup to support scrolling and paging horizontally so the user can flick left and right and each cell occupies the entire collection view frame.
Originally, I had no scrolling and the user would tap each cell to activate something in the app. Now that its a narrow frame where only one cell can be seen at a time I feel that tapping is redundant and the cell should simply be tapped in effect when it comes in view.
Is there a way to trigger an event such as didSelectItemAtIndexPath when a given UICollectionViewCell becomes the one displayed within my collection view's frame?
UICollectionView responds to selectItemAtIndexPath:animated:scrollPosition:.
It also responds to indexPathsForVisibleItems which will be useful to determine where to make the selection.
You also need to decide when to make the selection, probably best after receiving scrollViewDidEndDecelerating: which the delegate inherits from UIScrollViewDelegate).
But it may be even better advice to look at what your code does upon selection and just do that (launched from the same place in code, probably when scrolling is finished), leaving selection out of it.

Retaining UICollectionViewCell while scrolling a UICollectionView

I'm trying to figure out a way to keep a UICollectionViewCell from being removed (didEndDisplayingCell) from my UICollectionView when its original scroll position scrolls off of the view. I know this is the way a UICollectionView is supposed to work, that cells are removed and returned to the reuse pool when they are no longer visible, but this is based on their original position in the UICollectionView. I'm trying to drag that cell past the original visible area into a further away location, but it gets removed killing the pan gesture in progress and killing its view in the collection view once its original position is scrolled out of view. Is there a way to override this behavior and hold onto a UICollectionViewCell until I'm done with it?
I've seen the other ways to attack this problem by creating an image of the cell and dragging that instead, but that won't satisfy my purposes. I need the original cell to survive beyond its original screen position as I scroll through the UICollectionView.
Make copy when dragging your cell around and hide original cell.

UICollectionView does not reveal all cells in Simulator

I am not very experienced with UICollectionView and Auto-Layout.
I have a very basic UICollectionView inside a root view. The root view seems to have a Navigation Item.
I created a custom cell which is really a square in proper size to allow 2 such cells per row using the FlowLayout.
There are 8 such cells in the view - it is basically a grid. I have absolutely no constraints on the view.
The collection view occupies the entire size of the root view according to the IB and in the editor, the first cell is placed right under the navigation item which is perfect.
However, when I ran the app in the simulator and scrolled the collectionview all the way to the button, I see only a partial fragment of both cells in the last row. I can see I have scrolled all the way down...
Obviously there seems to be some sort of overflow...but I would have thought uicollectionview would automatically handle the overflow and make all the cells visible?
When I set number of items in IB I can see that the cells in the last row are only partially visible.
Seems like content size of the collection view is not right - that's my guess..
What do I need to do to adjust things in IB so that all of my cells are visible...I do not want to hardcode any values in the code...
Thanks.
Solved. It turns out simulator does not show the entire collection view...the same shows fine on the device... What a headache...

How to add empty cells in UITableView without expanding it

I have UITableView with custom looking cells. Now user can scroll past the bottom and see that there are no more rows (cells) and see background. I want to create impression that there are more rows below, but they should not be added to tableview, so when user scrolls down, it bounces back to last useful cell.
TableFooter and subview expands content and user can scroll there (or maybe I was doing it wrong).
Right now I added new empty cells and after any action that may recount contentSize I specifically set contentSize to default setting. But I feel like it's not the right way (although it works). Is there some other way?
I tried searching, but it's hard to explain what I want in few sentences, not to mention in search line.

Animating cells while UITableView is scrolling

I'm trying to achieve an effect wherein as a tableview is scrolling, the currently visible cells will animate according to where they are positioned on the screen. I'm somewhat new to IOS dev, so let me try to break it down:
Tableview loads with custom cells User begins scrolling While the
table is in motion, the visible cells have a UIView in which I would
like to perform an animation that corresponds directly to the cell's
current Y position on the screen.
Cells will ONLY animate when they
are visible
Cell animation directly corresponds to table motion, i.e.
whenever the table view scrolls, the cells are animating; once the
table stops, the animations pause
One solution I have thought of is to update drawRect every single frame when the tableview is moving. Depending on the graphic operations, this could be horrible performance wise. Is there a way to grab the current table position every time it changes? Would I be better suited to use Core Animation?
This might be helpful if you want to achieve something like below:
https://github.com/mrugrajsinh/AnimatedTableViewCellDemo
Make your view controllers the delegate of the UITableView, and use all the methods of scrollview Delegate also. There you have many controls for start scrolling and end scrolling, and within thpse controls you could check for uitableview cell positioning.
You have to become delegate to this: https://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UITableViewDelegate_Protocol/Reference/Reference.html
and this is the method to override and animate your cells:
– tableView:willDisplayCell:forRowAtIndexPath: