ios下拉刷新(PullRefreshTableView)

首先,将附件中的文件(Refresh)加入到项目中
然后,在Frameworks中添加QuartzCore.framework。
关键代码如下:
MainViewController.h文件

#import <UIKit/UIKit.h>

#import “PullRefreshTableViewController.h”

@interface MainViewController : PullRefreshTableViewController{

    NSMutableArray *items;

}

@end

MainViewController.m文件

– (void)viewDidLoad

{

    [super viewDidLoad];

    self.title = @”Pull to Refresh”;

    items = [[NSMutableArray alloc] initWithObjects:@”What time is it?”, nil];

}

– (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 [items count];

}

– (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    static NSString *CellIdentifier = @”Cell”;

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {

        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

    }

    // Configure the cell…

    cell.textLabel.text = [items objectAtIndex:indexPath.row];

    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    

    return cell;

}

– (void)refresh {

    [self performSelector:@selector(addItem) withObject:nil afterDelay:2.0];

}

– (void)addItem {

    // Add a new time

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init] ;

    [dateFormatter setTimeStyle:NSDateFormatterMediumStyle];

    NSString *now = [dateFormatter stringFromDate:[NSDate date]];

    [items insertObject:[NSString stringWithFormat:@”%@”, now] atIndex:0];

    

    [self.tableView reloadData];

    

    [self stopLoading];

}

demo下载地址:http://www.kuaipan.cn/file/id_82777686379857069.htm

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注