• 简单实现下拉刷新-----


    我的下拉刷新使用了系统在tableviewcontroller中自带的属性.使用了UIRefreshController这个类.如下为代码,其中RootViewControl继承自UITableViewController.以下为代码.非常简单的一个示例

    以下为.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
    
    以下为.h中的代码

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


  • 相关阅读:
    Python (一)Tkinter窗口组件:Label
    Python (八)Tkinter窗口组件:Scrollbar
    Python (四)Tkinter窗口组件:Radiobutton
    Python (五)Tkinter窗口组件:LabelFrame
    Python (三)Tkinter窗口组件:Checkbutton
    Scrapy安装及相关知识点概括
    Python (九)Tkinter窗口组件:Scale
    Python (六)Tkinter窗口组件:Entry
    电脑通过蓝牙适配器连接手机与蓝牙耳机之经验
    Noi2018 归途
  • 原文地址:https://www.cnblogs.com/xukunhenwuliao/p/3576234.html
Copyright © 2020-2023  润新知