zoukankan      html  css  js  c++  java
  • 简单实现下拉刷新数据

     1 #import "AppDelegate.h"
     2 #import "SearchController.h"
     3 @interface AppDelegate ()<UITableViewDataSource>
     4 @property (nonatomic,strong)UITableView *table;
     5 @property (nonatomic,strong)NSMutableArray *datas;
     6 @property (nonatomic,strong)UIRefreshControl *refreshControl;
     7 @end
     8 
     9 @implementation AppDelegate
    10 
    11 - (void)dealloc
    12 {
    13     self.datas = nil;
    14     self.table = nil;
    15     self.refreshControl = nil;
    16 }
    17 
    18 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    19     self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    20     self.window.backgroundColor = [UIColor whiteColor];
    21 
    22 
    23     [self setupViews];
    24     [self setupWithArray];
    25     
    26     [self.window makeKeyAndVisible];
    27     return YES;
    28     
    29 }
    30 /**
    31  *  初始化数组
    32  */
    33 - (void)setupWithArray
    34 {
    35     NSArray *array = @[@"A",@"B",@"C",@"D",@"E",@"F"];
    36     self.datas = [array mutableCopy];
    37 }
    38 /**
    39  *  添加控件
    40  */
    41 - (void)setupViews
    42 {
    43     self.table = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] bounds] style:UITableViewStylePlain];
    44     self.table.dataSource = self;
    45     [self.window addSubview:self.table];
    46     
    47     self.refreshControl = [[UIRefreshControl alloc] init];
    48     [self.refreshControl addTarget:self action:@selector(refreshControlChange:) forControlEvents:UIControlEventValueChanged];
    49     [self.table addSubview:self.refreshControl];
    50 
    51 }
    52 
    53 #pragma mark - 配置数据源
    54 /**
    55  *  @return 返回显示行数
    56  */
    57 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    58 {
    59     return self.datas.count;
    60 }
    61 /**
    62  *  显示内容
    63  */
    64 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    65 {
    66     static NSString *identify = @"cell";
    67     UITableViewCell *cell = [self.table dequeueReusableCellWithIdentifier:identify];
    68     if (cell == nil) {
    69         cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identify];
    70     }
    71     cell.textLabel.text = self.datas[indexPath.row];
    72     return cell;
    73 }
    74 /**
    75  *  每次下拉刷新,就添加新数据
    76  */
    77 - (void)refreshControlChange:(UIRefreshControl *)sender
    78 {
    79     static int count = 1;
    80     NSString *str = [NSString stringWithFormat:@"第%d次加数据",count];
    81     NSArray *array = @[str];
    82     NSMutableArray *newArray = [array mutableCopy];
    83     [newArray addObjectsFromArray:self.datas];
    84     self.datas = newArray;
    85     count++;
    86     /**  UITableView重新加载  */
    87     [self.table reloadData];
    88     /**   结束刷新 */
    89     [self.refreshControl endRefreshing];
    90 }
    91 @end

    刷新前                                                 刷新后

                

  • 相关阅读:
    数据结构与算法-字符串与字符串匹配算法
    操作系统-PV操作的原理和几种常见问题
    操作系统-进程(8)-临界区管理
    利用队列实现逐行打印杨辉三角形的前n行
    操作系统-进程(7)死锁和银行家算法
    计算机网络-网络层(6)ICMP协议
    操作系统-进程(6)管程
    计算机网络-链路层(5)点对点链路控制
    操作系统-进程(5)进程通信机制
    RTSP/RTMP流媒体协议网页无插件直播视频平台浏览器请求地址自带尾缀符解释说明
  • 原文地址:https://www.cnblogs.com/lantu1989/p/4604679.html
Copyright © 2011-2022 走看看