上下拉 刷新菜单

加入第三方 MJRefresh

导入头文件

6348937-bff674ded84dc1f1.png

定义全局变量 以及设置代理

6348937-ad2218a58e2efeb3.png
@interface ViewController (){
UITableView *table;
NSMutableArray *arr;
MJRefreshFooterView *foot;
MJRefreshHeaderView *header;
}

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//设置表格
table = [[UITableView alloc]initWithFrame:CGRectMake(0, 20, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
table.dataSource = self;
table.delegate = self;
[self.view addSubview: table];
arr = [NSMutableArray arrayWithObjects:@"123",@"345",@"123",@"345",@"123",@"345", nil];
foot = [MJRefreshFooterView footer];
foot.scrollView = table;
foot.delegate = self;
header = [MJRefreshHeaderView header];
header.scrollView = table;
header.delegate = self;
//开始刷新
[header beginRefreshing];
}

点击MJRefreshBaseViewDelegate 出来下一步

- (void)refreshViewBeginRefreshing:(MJRefreshBaseView *)refreshView{
if ([refreshView isKindOfClass:[MJRefreshHeaderView class]]) {
//2秒以后调用
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
// 10    1
[arr addObject:@"new123"];
//刷新表格
[table reloadData];
//停止刷新
[foot endRefreshing];
});
}else{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[arr removeObjectAtIndex:0];
//刷新表格
[table reloadData];
//停止刷新
[foot endRefreshing];
});
}
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return arr.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static  NSString *cellId = @"cellid";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
}
cell.textLabel.text = arr[indexPath.row];
return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return 1;
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 176,695评论 25 709
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 136,200评论 19 139
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 14,755评论 4 61
  • 日精进 郑州 坚持原创分享第83天 2017年9月19日 星期二 晴 “我这人比较直”——所以我出口伤人你也不能打...
    小莲蓬儿阅读 1,207评论 0 0
  • 今天老师带领我们学习了二维数组的录入,插入等知识,并带领大家完成了杨辉三角的输入。在学习中虽然有困难但通过努力还是...
    王子龙同学阅读 3,430评论 0 49

友情链接更多精彩内容