Detailed description of batch display data in iPhone tableview

Source: Internet
Author: User
Batch display of iPhone tableview data is the content to be introduced in this article, mainly about data display. The iPhone screen size is limited. If you need to display a large amount of data, you can first put the data into a table, first display 10, there are more options at the bottom of the table, click to view more and 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; this method of viewcontroller returns the number of data records: + 1 is used to display the cell-(nsinteger) for "loading more) tableview :( uitableview *) tableview numberofrowsinsection :( nsinteger) Section {int COUNT = [items count]; return count + 1;} This method customizes the display of cells, especially the cell "load more":-(uitableviewcell *) tableview :( uitableview *) tableview cellforrowatindexpath :( nsindexpath *) indexpath {If ([indexpath row] = ([items count]) {// create loadmorecell return loadmorecell;} // create your data Cell Return cell ;} you also need to process the selection event of the cell "load more" and trigger 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 mselectorin Background: @ selector (loadmore) withobject: Nil]; // [loadmorecell sethighlighted: No]; [tableview deselectrowatindexpath: indexpath animated: Yes]; return ;} // other cell events} Data Loading Method:-(void) loadmore {nsmutablearray * more; // load your data [self defined mselec1_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 withrowanim Ation: uitableviewrowanimationfade];} conclusion: I have finished introducing the batch display data in iPhone tableview. I hope this article will help you!

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.