I am working on an iphone application. Application loads plenty of records from a webservice into table view controller. I would like to load 25 records initially and remaining in 25 batch on clicking something like "Load 25 more" at the end of the table view.
Any help would be grealy appreciated.
Thanks
Just put a button connected to an Event in your table footer. When the button is clicked, append the next 25 results to your already existing array of items.
After that, just do a [self.tableView setNeedsDisplay]. I use that to let my table know I have extra data in the table. By using that, there is no need to scroll to the right line in the table, because it keeps its original position.
Also, why call the viewDidAppear method, this seems wrong to me, because (ofcourse) the view already appeared and all declerations and assignments you do there are re-done. Just put the stuff you need to be done while viewing the view AND when you are appending data in a seperate method and put call that method from your button-press event and from the viewDidAppear event.
I wrote an example project that does this which you can download from GitHub https://github.com/Abizern/PartialTable
I do almost the same in my application, getting 50 first records from webservice. As a table footer I have a view with next/previous buttons, that when pressed launch a fetching request for next/previous 50 results. After fetch request is processed I call viewWillAppear:animated: for my view controller and inside to [self.tableView reloadData], so these results show up in the same table view. Of cause I'm keeping the data each time only for presented results, but it depends on your needs.
Hope this helps
I wrote something that does exactly what you describe, an put it on github : https://github.com/nmondollot/NMPaginator
It encapsulates pagination, and works with pretty much any webservice using page and per_page parameters. It also features a UITableView with automatic fetching of next results as you scroll down.
Hope it'll be useful.
Related
I'm developing an iOS application in which i have a UITableView containing list of people coming from web-service and i have a more button on bottom. When user clicks on more it calls a service which provides some new people for the list. Now i want to add this list with the previous tableView list without reloading the whole tableView. how do i achieve this.
Any help would be really appreciable. I can provide my code of more button where i'm calling the service to get the data from service.
UITableview provides several APIs for manipulating the content. You should use the
- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation: (UITableViewRowAnimation)animation;
method. The way how they should be applied is described in the Table View Programming Guide.
Practically, when the button is clicked, you start the network request for the list of names and when that finishes, you add the rows to the table with the above API.
Note: as long as you do only this modification to the table view, you don't have to use the beginUpdates, endUpdates methods. If there are multilple changes carried out at once (deletion, addition, reordering) then the beginUpdates/endUpdates is necessary.
Have a look at UITableView's - beginUpdates; and - endUpdates method.
In between calling these you'd have to insert the rows into the table view. If you are using UITableView's - insertRowsAtIndexPaths:withRowAnimation: method you can even skip the begin- and endUpdates.
Make sure to insert your new objects to your data source object before calling insertRowsAtIndexPaths:withRowAnimation:.
If you don;t want to reload the table then, at least, you have to call
insertRowsAtIndexPaths: withRowAnimation:
except that you can't show the newly added data in your table view.
As per my experience , It is not possible to add/display new names to table view without reloading it.
But you can achieve your task as follows ;
You can set arraCount(one varaible) for namesArray count. After calling webservice, you can increment arrayCount varaiable and reload the table view , which will display new added names in the table.
Hope this will help.
I have UITableView, which I fill from a JSON Query.
I fill it with Private Messages and it works.
The JSON Query has the properties of "site" in which I get for every site 20 PMs. So at the beginning I got Site=0 and got 20PMS which are loaded.
Now I wanna have the features like in the Email-app (i believe I saw it there): When you scroll down and reach the end (in my app reached the 20. PM), the application should load the next 20 and so on and so on.
Any ideas how to realize?
Save the index path of your last row and implement
[UITableView reloadRowsAtIndexPaths:withRowAnimation:]
Or you can use scrollToRowAtIndexPath:atScrollPosition:animated:
scrollPosition
A constant that identifies a relative position in the receiving table view
(top, middle, bottom) for row when scrolling concludes.
See “Table View Scroll Position” a descriptions of valid constants in docs
And once you get you last scroll position just reload your table view [tableView reloadData]
But there is problem i guess once you reload the data i think after reloading(I am not sure) tableView it will take you to first row again then you can always save the lastIndexpath of that tableView and after reloadData just scrollToRowAtIndexPath:atScrollPosition:animated: or you can use scrollToNearestSelectedRowAtScrollPosition:animated:
I think you can implement feature like email app using your custom logic. What you do is keep the last row of tableview for loading more data. There should be message like "Load more..." in that last row. Whenever user touches that row, you should load more data and update tableview.
Stephen James and his colleagues at Key Options Development came across a similar problem: http://blog.keyoptions.co/tableview-with-automatic-load-more
They have built a sample app (ContinousTableview) that should be of some help to you. The source code is available at GitHub: https://github.com/stephenjames/ContinuousTableview
I have made an uitableView and I am fetching data from json from a webservice
now i want that I get first 20 object first and load it in my tableView. it is happening properly
Now I want that when user scroll to the footer ..next 20 data should be fetched and it should be shown in tableView..
I am stuck here ..can anyone give me any idea how to proceed next?
May be you can put Load more button in footerview and by tapping that you can load another 20 records from server ?
Another method is to implement Pull To Refresh and modify it as per your need.
You can use a ready made implementation of a UITableView with pull-to-refresh functionality.
Have a look at EGOTableViewPullRefresh or for a simpler implementation to PullToRefresh.
If you are interested in implementing this yourself, one approach is to add a subview to your UITableView (e.g., UILabel showing the "pull to refresh" message); then "intercept" the delegate methods when the user scrolls down (or up) and calculate whether the subview came into the viewable frame. Then issue the reload.
Another approach would be adding a last row to your table; then when the tableView:cellForRowAtIndexPath: method of your data source is called, return a cell with the "pull to refresh" message and do the refresh.
But you will be better off using one of the suggested implementations.
To know if you reached the button of the table (aka: seeing the footer) I think you could use this:
How to know when UITableView did scroll to bottom in iPhone
This is the situation:
A user filters a database by selecting keywords from a list, then presses "search". This pushes an instance of a UITableViewController subclass onto the navigation stack.
In the viewWillAppear: method, data are fetched from Core Data and stored in an ivar, ready for the table view's data source and delegate methods.
So far so good.
The UI problem arises when there are no results.
This simple architecture means that an empty result set yields an empty table view with no explanations.
It would be good for the UI to tell the user something like "Your search gave no results, please try with fewer keywords".
My question is this:
What is the best way to provide relevant feedback to the user, without having to change the architecture too much?
I was thinking about using the table header, but what do my esteemed colleagues here think?
Using the table header is not a bad option. You can go for that. You can also try other options like showing the info in a simple label or perhaps even an alert. But personally I wouldnt recommend the alert.
U can show that in UIAlertView.
You could add / show a UILabel to your view that says "No search results" (or something like that) when the table does not contain any data.
After fetching the result from core data... just count the number of rows in the result and then before displaying Table View just check if Count>0 then only go for table view ... else just display UIAlertView... this will save u from unnecessary display of UITableView
You can put AlertView when your ivar is empty and in alert button index return to the main view from where you are entering your search. This is the best way for you without changing your architecture.
I'm building an app (not necessarily a twitter client) and I'm trying to figure out how developers create the buttons above and below a table view where a user presses them to either reload newer data or reload older data into a table view. Does anyone know of any tutorials out there that does this or know of an easy way?
If you want fixed buttons, you can just make your table view not use the full screen and add the buttons in the space. If you want the buttons to scroll with the table view, you can add a header or footer view to the table and put your buttons inside that.
Check the Three20 project. I believe there's a tableview there that does that.
It's actually not that hard to add inline buttons to a tableview. First you check and see if there's actually more data to show. If so, you want to add 1 to the number of rows returned from the datasource. When asked to draw that last row you return a cell that contains "Press for more" caption as well as a hidden spinner instead of the standard cell that shows your normal data.
If the user presses that last button the table view handler turns on the spinner then fires off a network event. Once the network request completes the data is processed and added to the same tableview datasource that was used to draw the first table.
Now all you have to do is tell the tableview to reload itself and the new data will show up. If you want to limit the amount of data shown you can prune out N number of items from the head of the datasource before redrawing so the memory-use stays manageable.