Uitableview for iOS development UI display -- paging Loading

Source: Internet
Author: User

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.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.