zoukankan      html  css  js  c++  java
  • 简单实现---下拉刷新 --使用UITableViewController中的refreshControl属性

    和上文一样,也是一个简单的根视图控制器直接加载.其中的数组模仿了真实的数据加载.直接把数组更改为数据库拿去数据即可,其中涉及到主要就是新开了一个线程,本文主要解释了以下实现的原理,如果涉及到从网络获取数据的问题,看懂本文之后请自行百度,估计就可以看懂了.

    以下为.h文件

    #import <UIKit/UIKit.h>
    
    @interface RootViewController : UITableViewController
    @property (retain,nonatomic) NSMutableArray *arr;
    @end
    以下为.m文件

    #import "RootViewController.h"
    
    @interface RootViewController ()
    
    @end
    
    @implementation RootViewController
    
    - (id)initWithStyle:(UITableViewStyle)style
    {
        self = [super initWithStyle:style];
        if (self) {
            self.arr = [[NSMutableArray alloc] initWithCapacity:5];
            [self.arr addObject:@"123"];
            [self.arr addObject:@"123"];
            [self.arr addObject:@"123"];
            [self.arr addObject:@"123"];
            [self.arr addObject:@"123"];
            [self.arr addObject:@"123"];
        }
        return self;
    }
    - (void)viewWillAppear:(BOOL)animated
    {
        
    }
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        self.refreshControl = [[UIRefreshControl alloc] init];
        self.refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:@"谁离了谁累死了当拉拉队"];
        [self.refreshControl addTarget:self action:@selector(a) forControlEvents:UIControlEventValueChanged];
    
        
    }
    - (void)a
    {
        NSLog(@"1234");
        [self performSelector:@selector(handleData) withObject:nil afterDelay:2];
    
    }
    - (void)handleData
    {
        [self.refreshControl endRefreshing];
        NSLog(@"nidaye");
        [self.arr addObject:@"123"];
        [self.tableView reloadData];
    }
    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    #pragma mark - Table view data source
    
    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
        // Return the number of sections.
        return 1;
    }
    
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        // Return the number of rows in the section.
        return [self.arr count];
    }
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *CellIdentifier = @"Cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]autorelease];
        }
        cell.textLabel.text = [NSString stringWithFormat:@"%d",[self.arr count]-indexPath.row];
        NSLog(@"这说明正在复用");
        return cell;
    
    }
    
    @end
    


  • 相关阅读:
    display:inline-block引发的间隙思考
    HTML中让表单input等文本框为只读不可编辑的方法
    纯CSS实现箭头、气泡让提示功能具有三角形图标(简单实例)
    区分javascript中的toString(),toLocaleString(),valueOf()方法
    Javascript高级程序设计笔记 <第五章> 引用类型
    js数组操作大全
    css中使用if条件在各大浏览器(IE6IE7IE8)中hack方法解决教程
    IE下判断IE版本的语句...[if lte IE 8]……[endif]
    有关opacity或RGBA设置颜色值及元素的透明值
    traceback模块——获取详细的异常信息
  • 原文地址:https://www.cnblogs.com/xukunhenwuliao/p/3576205.html
Copyright © 2011-2022 走看看