In iOS, due to screen size restrictions, if you need to display a lot of data, you need to use paging loading.
Principle: first put the data into a table, first display 10 items, at the bottom of the table to view more options, click to view more to view the remaining parsed data. Basically, there are only 10 entries in the data source. When you click the last cell, add more data to the data source. For example:
The data source is an array:
Nsmutablearray * items;
The number of data entries returned by this method of viewcontroller: + 1 is used to display the cell "load more"
-(Nsinteger) tableview :( uitableview *) tableview numberofrowsinsection :( nsinteger) Section {
Int COUNT = [items count];
Return count + 1;
}
This method is used to customize the cell display, especially the cell that "loads more:
-(Uitableviewcell *) tableview :( uitableview *) tableview cellforrowatindexpath :( nsindexpath *) indexpath {
If ([indexpath row] = ([items count]) {
// Create loadmorecell
Return loadmorecell;
}
// Create your data cell
Return cell;
}
It also processes the selection event of the cell "load more" and triggers a method to load more data to the list.
-(Void) tableview :( uitableview *) tableview didselectrowatindexpath :( nsindexpath *) indexpath {
If (indexpath. Row = [items count]) {
[Loadmorecell setdisplaytext: @ "loading more..."];
[Loadmorecell setanimating: Yes];
[Self defined mselectorinbackground: @ selector (loadmore) withobject: Nil];
// [Loadmorecell sethighlighted: No];
[Tableview deselectrowatindexpath: indexpath animated: Yes];
Return;
}
// Other cell events
}
How to load data:
-(Void) loadmore
{
Nsmutablearray * more;
// Load your data
[Self defined mselecw.mainthread: @ selector (appendtablewith :) withobject: More waituntildone: No];
}
Add data to the list:
-(Void) appendtablewith :( nsmutablearray *) data
{
For (INT I = 0; I <[Data Count]; I ++ ){
[Items addobject: [data objectatindex: I];
}
Nsmutablearray * insertindexpaths = [nsmutablearray arraywithcapacity: 10];
For (INT ind = 0; ind <[Data Count]; ind ++ ){
Nsindexpath * newpath = [nsindexpath indexpathforrow: [items indexofobject: [data objectatindex: Ind] insection: 0];
[Insertindexpaths addobject: newpath];
}
[Self. tableview insertrowsatindexpaths: insertindexpaths withrowanimation: uitableviewrowanimationfade];
}
I am writing dead data here. For example, in the Implementation Project, for example, to request data from the server, the total number of pages of data returned will usually be one page at a time, when you need to view more pages, slide to the bottom cell and request the next side!
In my example, the request loading is mostly written to the didselectrowatindexpath: proxy method. If you need to automatically load it, you can put it in-(void) tableview :( uitableview *) tableview willdisplaycell :( uitableviewcell *) cell forrowatindexpath :( nsindexpath *) indexpath
Proxy method.