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:
- 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];
- }
Summary: DetailsIPhone TableviewBatch displayDataI hope this article will help you!