Detailed description of batch display data in iPhone Tableview

Source: Internet
Author: User

IPhone TableviewBatch displayDataIs the content to be introduced in this article, mainly to explain isData. IPhone screen size is limited, if you need to displayDataA lot.DataPut it in a table and display 10 items first. Check more options at the bottom of the table and click View More to view the remaining items of the resolution.Data. BasicallyDataAdd only 10 entries in the source. When you click the last cell, add moreDataToDataSource. For example:

The data source is an array:

 
 
  1. NSMutableArray *items; 

The number of data entries returned by this method of ViewController: + 1 is used to display the cell "load more"

 
 
  1. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {  
  2.         int count = [items count];  
  3.     return  count + 1;  

This method is used to customize the cell display, especially the cell that "loads more:

 
 
  1. -(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath {
  2. If ([indexPath row] = ([items count]) {
  3. // Create loadMoreCell
  4. Return loadMoreCell;
  5. }
  6. // Create your data cell
  7. Return cell;
  8. }

It also processes the selection event of the cell "load more" and triggers a method to load more data to the list.

 
 
  1. -(Void) tableView :( UITableView *) tableView didSelectRowAtIndexPath :( NSIndexPath *) indexPath {
  2. If (indexPath. row = [items count]) {
  3. [LoadMoreCell setDisplayText: @ "loading more..."];
  4. [LoadMoreCell setAnimating: YES];
  5. [Self defined mselectorinbackground: @ selector (loadMore) withObject: nil];
  6. // [LoadMoreCell setHighlighted: NO];
  7. [TableView deselectRowAtIndexPath: indexPath animated: YES];
  8. Return;
  9. }
  10. // Other cell events
  11. }

How to load data:

 
 
  1. -(Void) loadMore
  2. {
  3. NSMutableArray * more;
  4. // Load your data
  5. [Self defined mselecw.mainthread: @ selector (appendTableWith :) withObject: more waitUntilDone: NO];
  6. }

Add data to the list:

 
 
  1. -(void) appendTableWith:(NSMutableArray *)data  
  2. {  
  3.     for (int i=0;i<[data count];i++) {  
  4.         [items addObject:[data objectAtIndex:i]];  
  5.     }  
  6.     NSMutableArray *insertIndexPaths = [NSMutableArray arrayWithCapacity:10];  
  7.     for (int ind = 0; ind < [data count]; ind++) {  
  8.         NSIndexPath    *newPath =  [NSIndexPath indexPathForRow:[items indexOfObject:[data objectAtIndex:ind]] inSection:0];   
  9.         [insertIndexPaths addObject:newPath];  
  10.     }  
  11.     [self.tableView insertRowsAtIndexPaths:insertIndexPaths withRowAnimation:UITableViewRowAnimationFade];  
  12. }  

Summary: DetailsIPhone TableviewBatch displayDataI hope this article will help you!

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.