博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UITableView分页
阅读量:7066 次
发布时间:2019-06-28

本文共 2240 字,大约阅读时间需要 7 分钟。

UITableView分页上拉加载简单,ARC环境,源码如下,以作备份:

原理是,点击最后一个cell,触发一个事件来处理数据,然后reloadData

RootViewController.m + RootViewController.h

#import "RootViewController.h"@interface RootViewController ()
@property (nonatomic, strong) UITableView *tableView;@property (nonatomic, strong) NSMutableArray *dataSource;@end@implementation RootViewController- (void)viewDidLoad{ [super viewDidLoad]; _dataSource = [[NSMutableArray alloc] init]; for (int i = 0; i < 10; i++) { [_dataSource addObject:[NSString stringWithFormat:@"%d", i]]; } _tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain]; _tableView.dataSource = self; _tableView.delegate = self; [self.view addSubview:_tableView];}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ // 因为要定制最后一行,所以cell多一个 return _dataSource.count + 1;}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *reusedStr = @"demo"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reusedStr]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reusedStr]; } if([indexPath row] == ([_dataSource count])) { // 定制最后一行的cell cell.textLabel.text=@"获取更多.."; } else { // 定制普通行的cell cell.textLabel.text=[_dataSource objectAtIndex:[indexPath row]]; } return cell;}- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ // 如果是最后一行点击事件,则触发一个事件 if (indexPath.row == ([_dataSource count])) { [self performSelectorInBackground:@selector(loadMore) withObject:nil]; [tableView deselectRowAtIndexPath:indexPath animated:YES]; return; }}- (void)loadMore{ // 添加数据源 for (int i = 0; i < 10; i++) { [_dataSource addObject:[NSString stringWithFormat:@"新%d", i]]; } // 重新加载tableView [_tableView reloadData];}@end
#import 
@interface RootViewController : UIViewController@end

转载地址:http://fgall.baihongyu.com/

你可能感兴趣的文章
EX2010与EX2013共存迁移04-Exchange 2013配置
查看>>
<kubernetes in action>看书笔记
查看>>
python密码破解工具patator
查看>>
众筹网站Kickstarter不准备上市:转型公益企业
查看>>
OpenStack入门修炼之nova服务(计算节点)的部署与测试(11)
查看>>
ubuntu安装apache php mysql phpmyadmin
查看>>
漫画: DBA和小D的日常
查看>>
构建高可用服务器之一 Keepalive介绍及安装
查看>>
Android Studio第四十期 - 上传头像功能支持权限管理
查看>>
系统generate excel格式的报告时,日期显示错误
查看>>
代码 实现UIDatePicker控件 和 Tab Bar 视图切换
查看>>
iOS学习——iOS系统架构(三)
查看>>
AndroidUI优化工具——HierarchyViewer
查看>>
MyBatis多参数传递之默认命名方式示例——MyBatis学习笔记之十二
查看>>
USB引导盘制作
查看>>
一线网络工程师需要注意的十个非技术细节
查看>>
UML建模之状态图(Statechart Diagram)
查看>>
perl CPU利用率
查看>>
IT小妙招:请走开!自作聪明的Windows 7边缘最大化
查看>>
Insufficient system resources exist to complete the requested service
查看>>