UITableView -> How to load additional entry on scroll down? - ios

I want to load my data on scroll down for my tableView.
I have a JSON API from where I get my data.
Its a Private Message System.
Everytime I will get 20 entries, I can select a page (0 to x) get the first to x entries (everytime 20 entries).
So at the moment I have my table and I load a list of 20 entries and show them.
Now I want to have as soon as I reach the last entry it should load the next 20 entries.
I try to read many things about it here on StakcOVerflow and look at a Github Project with this but don't understand it at all.
Can someone tell me how to do this?

You can use the willDisplayCell method of UITableview. For ex, to see whether a row has 'load-more' button if you have one.
See this post.
A Github project.

you can implement this delegate
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
//put data on your array
[tableView reloadData];
}

Related

Pattern for no data in a section in collectionView/TableView

I am contemplating on what is the recommended way to display a notice that there is no data for a specific section in a collectionView/TableView
One way is to create a special cell and to put that in instead of the data cells. That feels odd, since the "empty notice" cell doesn't correlate with the data, which means I would need to spread a lot of conditions in didSelectItem, configuring the cell, etc
Using https://github.com/dzenbot/DZNEmptyDataSet is appropriate only when the entire view is empty, not in a specific section
Another way would be (which is what I do now) to insert a UIView into the place where the data would be as a subview of the collectionview, But this also would require maintenance when reloading the data, scrolling, tapping. Also this requires calculation of where to place the view, which means I need to change it per collectionview, since it is not part of the collectionviewlayout
Is there a recommended pattern to deal with these situations?
Maybe you shouldn't have that section at all if the section contains empty data. Reduce section count by 1 at - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView datasource method and recheck the cell to be displayed during - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath datasource method.
In reply to you, I think you would have some type of "Add" button to add comments, photos, friends, etc. Make the option to add a comment or photo less obtrusive than taking an entire tableView row, and omit the comment or photo section, if there are no comments or photos.
If you put an "Add comment" or "Add photo" row while displaying details, users will likely get tired of unnecessarily reading that, as they use the app.
Note that tableViews generally handle insertion in editing mode, and when not editing, no section is shown if it is empty.

Infinite Scroll on iOS with Swift

I'm an iOS newbie and I would like to know how to detect when the user scrolls and reaches the bottom of an UITableView so I can load new data into the table.
I would also like to know where such a method should be implemented (the tableview's class or the view controller in which this tableview exists)
Cheers!
You can use -(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath to and check if the last cell will be shown in the TableView's data source.
iOS' TableViewController takes care of that automatically. It asks its datasource only for the currently visible rows of the table (tableview.cellForRowAtIndexPath)
See the documentation for the UITableViewDatasource Protocol Reference
If you've got a "known dataset" (as in, you don't need to make a network call to fetch new data), then like #zizoft said, it'll be handled automatically in tableview.cellForRowAtIndexPath
If, however, you've got an "unknown dataset", (as in, you'll need to pull down data from the internet), you'll need to do something a bit more interesting - #ansible's suggestion would be appropriate in that case.

How do I impletment infinite scrolling for a blog app using RSS?

I was wondering if it is possible to implement infinite scrolling for a app that displays my blog's RSS feeds? Kind of like Instagram or Facebook when you scroll to the bottom it fetches more feeds. Can the same be done for an app using RSS feeds?
Implement this UITableView Delegate method:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
And do a check on your datasource array count with the indexPath of the row.
Then add more data to your array with a custom method
yes this will be possible - you will likely need to implement the logic for this yourself though. Check out this post:
http://michele.berto.li/infinite-scroll-on-ios-with-uitableview/
Look at this component : https://github.com/samvermette/SVPullToRefresh. There's a category which contains a method :
[tableView addInfiniteScrollingWithActionHandler:^{
// append data to data source, insert new cells at the end of table view
// call [tableView.infiniteScrollingView stopAnimating] when done
}];
You can look at the sample, it provides you a pretty way to implement that.

UITableView accessory view

I have created a UITableView populated by data coming from mysql (using NSJSONSERIALIZATION). Now the problem is one thing. What I retrieved was the product name. I want to have an accessory view (arrow like on the right side of cell). once clicked, new view and load details of that product there.
I know it can be done, but don't know how or where to look for a good tutorial. Any recommendations?
am really new to iOS development.
thanks a lot
Use this tableview delegate.
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
...and in cellForRowAtIndexPath: add this.
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;

Inability to delete table cells after a certain point

I have built an app which has the ability to delete cells from a table, but only if there are more than two cells.
If there are two or less cells, it only lets me select them. Any ideas?
Here's a video to visualize it: http://slavingia.com/etc/helpme.mov
If you have the datasource, in the delegate method
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
you can see how many items are in the source, if its less than 2 then you can return none in this method which wont allow editing, otherwise you can return delete style so you can

Resources