zoukankan      html  css  js  c++  java
  • 下拉刷新、上拉加载更多

    1、系统控件UIRefreshControl

    使用方法:

    只对UITableviewController有用;
    不能上拉刷新;
    init或者viewdidload中创建UIRefreshControl,设置文字,颜色等信息;
    系统自动管理UIRefreshControl,自动添加到tableview视图中;
    给UIRefreshControl添加方法,当值改变的时候调用,方法用于数据请求;
    该方法中请求数据确认完成之后,调用endRefreshing方法,关闭刷新;
    #import "ViewController.h"
    
    @interface ViewController ()
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        [self setupRefresh];
    }
    
    /**
     *  集成下拉刷新
     */
    -(void)setupRefresh
    {
        //1.添加刷新控件
        UIRefreshControl *control=[[UIRefreshControl alloc]init];
        control.attributedTitle = [[NSAttributedString alloc] initWithString:@"努力加载中……"];
        control.tintColor = [UIColor grayColor];
        [control addTarget:self action:@selector(refreshStateChange:) forControlEvents:UIControlEventValueChanged];
        [self.tableView addSubview:control];
        
        //2.马上进入刷新状态,并不会触发UIControlEventValueChanged事件
        [control beginRefreshing];
        
        // 3.加载数据
        [self refreshStateChange:control];
    }
    
    /**
     *  UIRefreshControl进入刷新状态:加载最新的数据
     */
    -(void)refreshStateChange:(UIRefreshControl *)control
    {
        
        NSLog(@"刷新了");
        [control endRefreshing];
    }
    
    @end
    View Code

    效果图

  • 相关阅读:
    牢骚
    【题解】LFYZNoip前水题赛 T6
    【模板】 ST表
    【模板】高精度。。。。。
    【模板】堆优化 + dij +pair 存储
    【模板】树状数组
    近两天目标
    当堆遇到STL 代码焕发光芒
    【模板】并查集
    【NOI2000】 单词查找树
  • 原文地址:https://www.cnblogs.com/imChay/p/5591573.html
Copyright © 2011-2022 走看看