Dynamic tableview with paging - ios

I want to create table view in which paging is required but i want an extra feature like if one cell is added to bottom then one cell will be removed to top
for example
if table have 100 rows and user scroll to bottom app call to server and load another 20 rows at bottom and on same time 20 rows from top will be removed.
if user scroll to top then app call to server and load 20 cell to top and remove 20 cell to bottom.
in short anyhow table have 100 cells only depending on scroll direction cell will be added on top or bottom

To get Extra Feture
You have to maintain data states to get successively record for new 20 on scroll to down or to get old 20 records on scroll up.
A data source array with capacity of 20 items.
On scroll to down last row/scroll to up first row prvious items array replaced by new getted items.
4.Reload tableView.
It will be updated tableview with new 20 items.

You can maintain the offset and limit for your number of results.
Based on the previous offset, you can ask for the next set of results to load in the tableview.
And you can hit API to load result in willDisplayCell:forRowAtIndexpath method of UITableView when the indexPath.row is greater than or equal to your number of results while scrolling down and while scrolling up you can check for indexpath.row == 0 to hit the api to produce previous 20 results.

What you are looking for is "Infinite Scroll"
A Quick Search brought me following results:
https://stackoverflow.com/a/10404477/2753395
https://github.com/pronebird/UIScrollView-InfiniteScroll

Related

How to handle flickering and blank space issues while reloading the tableview?

I am using Xamarin iOS and my table view contains multiple types of cells.
All the cells have dynamic height and different contents with multiple sections.
Here suppose I have total 10 cells out of which few are visible and others are hidden. Based on user action, It depends on whether to show or hide the cell.
In this scenario, If the number of cells is less, It's somehow working fine. But flickering and blank space are showing when the number of cells increases.
You need to reload only appropriate section or even rows instead of reload whole tableview.
Please checkout this solutions.
Reload sections in UITableView

TableView reload not setting UITableView section height

I am working on a UITableView which has 2 sections, both of which have exactly 1 row which is a custom cell. This custom cell has a collection view which is used to display various products.
Specific to my issue, the two collection views have 6 cells(three rows in the collection view). However when I load the page, the second section only displays 4 cells (two rows in the collection view). I am using UITableViewAutomaticDimension for the tableview which has the cells that contain these collection views.
I have tried using setLayoutNeeded and layoutIfNeeded, I am calling reload data on the tableView in a number of places. I am reloading the second section specifically as well. However the only way the cell's dimensions get fixed is if I scroll down to the second section, then scroll up to the first and then go back to the second.
I have been stuck on this for the past 3 days and absolutely any help would be greatly appreciated.
However the only way the cell's dimensions get fixed is if I scroll
down to the second section, then scroll up to the first and then go
back to the second.
According to this, I think you should reload your collection views firstly. And then reload your table view.

Shows bottom section of table view at visible view

I know the title is confusing. So I explain what I expect.
I have 3 sections in my table view. The first section has one or more rows. And second and third sections has only one row. When the first section has more than 4 rows the next sections going to be visible by scrolling table view bottom.
But I need these sections be visible in this case.
Actually I need show these sections at the bottom of the visible frame when first section has more than 4 rows!
Is it possible ?
The thing you can do it to display only the 3 first rows of the first section and then when the user starts scrolling, you add the additional cells to the first section while he is scrolling until you've added all of your cell.
Do the opposite when scrolling to top.
You can use two different TableView instead of one.
declare first TableView with only one section & seconds TableView with two section with one row each.
for that you need to use UIViewController instead of UITableViewController.
in this way your bottom TableView Cell always stay visible while first TableView can scroll with more cells.

How many cells table view uses

I have 100 rows of data but when we i run the code in iPhone Retina(4-inch) simulator i can see only 14 fit on the screen at a time. If i count the number of visible rows then i get up to 13 but it’s possible to scroll the table in such a way that the top cell is still visible and a new cell is pulled in from below. So that makes at least 14 cells.
If you scroll really fast, then I guess it is possible that the table view needs to make a few more temporary cells, but I’m not sure about that.I want to know after how many cells a cell get reused?

UITableView sections to always stay within view

I have a UITableView with 3 sections:
section 1:
the header title of this section is "Players" and the cotent is exactly 1 cell containing a horizontal list of 1-4 players names.
section 2:
the header title of this section is "Rounds" and the content is X cells each containing a horizontal list of each respective players score for round X.
section 3:
the header title of this section is "Totals" and the content is exactly 1 cell containing the sum of each player's round scores.
Right now, all these sections scroll as section 2 expands with new rounds, but I want to always keep section 1 at the top of the screen, and have section 3 right below section 2, until it expands down to the bottom of the screen and then stop and stay there.
I guess I could do this with 3 separate table views inside a UIView but that seems kind of convoluted and I section 3 wouldn't stay right below section 2 until it expanded to the bottom of the screen; it would just always be at the bottom...
Is there a way to keep a table section/row always visible, and have the others still scrollable?
Use 3 UITableViews as you discussed, and just animate the position of the Third tableview to move it down each time you add a cell to tableView 2, until it reaches the bottom of the screen then just leave it there. (Also you will need to expand the height of tableView 2 as you add elements to it.)
Otherwise, like Cyrille said, there is no way to implement that with one tableview only.
Not with the standard UITableView implementation, no.

Resources