#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