zoukankan      html  css  js  c++  java
  • iOS 上拉刷新和下拉加在更多(第三方框架EGOTableViewPullRefresh)

    #import <UIKit/UIKit.h>
    
    @interface AppDelegate : UIResponder <UIApplicationDelegate>
    
    @property (strong, nonatomic) UIWindow *window;
    
    
    @end
    #import "AppDelegate.h"
    #import "RootViewController.h"
    @interface AppDelegate ()
    
    @end
    
    @implementation AppDelegate
    
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        // Override point for customization after application launch.
        self.window.backgroundColor = [UIColor whiteColor];
        
        self.window.rootViewController = [[RootViewController alloc] init];
        
        [self.window makeKeyAndVisible];
        return YES;
    }
    
    
    @end
    #import <UIKit/UIKit.h>
    
    @interface RootViewController : UIViewController
    
    @end
    //  EGOTableViewPullRefresh框架的链接: http://pan.baidu.com/s/1qWVhVPy 密码: 2p7k
    
    #import "RootViewController.h"
    #import "PullTableView.h"
    @interface RootViewController ()<PullTableViewDelegate,UITableViewDataSource,UITableViewDelegate>
    {
        PullTableView *_tableView;
        NSMutableArray *data;
        int page;
    }
    @end
    
    @implementation RootViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        //初始化数组
        data = [[NSMutableArray alloc] init];
        page = 1;
        //初始化_tableView
        _tableView = [[PullTableView alloc] initWithFrame:[[UIScreen mainScreen] bounds] style:UITableViewStylePlain];
        _tableView.dataSource = self;
        _tableView.delegate = self;
        //设置pullDelegate代理
        _tableView.pullDelegate = self;
        [self.view addSubview:_tableView];
        //请求数据
        [self requestDataWithPage:page];
    }
    /**
     *  数据
     */
    - (void)requestDataWithPage:(int)number{
        int count = number * 10;
        for (int i = 0; i < count; i++) {
            [data addObject:[NSString stringWithFormat:@"%d",i]];
        }
    }
    #pragma mark -- tableview 数据源配置 --
    //返回多少个区
    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
        return 1;
    }
    //返回相应的区的行数
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
        return data.count;
    }
    //返回cell的高度
    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
        return 60;
    }
    // 配置cell的数据
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
        static NSString *identifier = @"cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        }
        //注意:使用数据源时要进行判断(data.count != 0),否则程序会崩溃
        if (data.count != 0) {
            cell.textLabel.text = data[indexPath.row];
        }
        return cell;
    }
    #pragma mark -- PullTableView 代理 --
    - (void)pullTableViewDidTriggerRefresh:(PullTableView *)pullTableView{
        [self performSelector:@selector(refresh) withObject:nil afterDelay:0.3f];
    }
    
    - (void)pullTableViewDidTriggerLoadMore:(PullTableView *)pullTableView{
        [self performSelector:@selector(loadmore) withObject:nil afterDelay:0.3f];
    }
    /**
     *  刷新
     */
    - (void)refresh{
        [self clearData];
        page = 1;
        [self requestDataWithPage:page];
        _tableView.pullLastRefreshDate = [NSDate date];
        //停止刷新
        _tableView.pullTableIsRefreshing = NO;
        [_tableView reloadData];
    }
    /**
     *  加载更多
     */
    - (void)loadmore{
        [self clearData];
        page++;
        [self requestDataWithPage:page];
        _tableView.pullTableIsLoadingMore = NO;
        [_tableView reloadData];
    }
    /**
     *  清空数组
     */
    - (void)clearData{
        [data removeAllObjects];
    }
    
    @end
  • 相关阅读:
    HDU 5791 Two (DP)
    POJ 1088 滑雪 (DPor记忆化搜索)
    LightOJ 1011
    POJ 1787 Charlie's Change (多重背包 带结果组成)
    HDU 5550 Game Rooms (ccpc2015 K)(dp)
    HDU 5542 The Battle of Chibi (ccpc 南阳 C)(DP 树状数组 离散化)
    HDU 5543 Pick The Sticks (01背包)
    HDU 5546 Ancient Go (ccpc2015南阳G)
    NB-IoT的DRX、eDRX、PSM三个模式 (转载,描述的简单易懂)
    MQTT 嵌入式端通讯协议解析(转)
  • 原文地址:https://www.cnblogs.com/lantu1989/p/5090438.html
Copyright © 2011-2022 走看看