iOS 上拉刷新和下拉加在更多(第三方框架EGOTableViewPullRefresh)
2024-10-19 00:22:33
#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 = ;
//初始化_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 * ;
for (int i = ; i < count; i++) {
[data addObject:[NSString stringWithFormat:@"%d",i]];
}
}
#pragma mark -- tableview 数据源配置 --
//返回多少个区
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return ;
}
//返回相应的区的行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return data.count;
}
//返回cell的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return ;
}
// 配置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 != ) {
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 = ;
[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
最新文章
- SQLSERVER中如何快速比较两张表的不一样
- no leveldbjni64-1.8 in java.library.path
- SDIO接口
- 原 Linux搭建SVN 服务器
- 简单模拟java动态动态代理机制的底层实现原理
- Windows配置Python编程环境
- C#连接oracle数据库提示ORA-12154: TNS: 无法解析指定的连接标识符
- 用人类社会工程学对C语言中的一些基本概念的剖析与理解
- No space left on device Linux系统磁盘空间已满
- 使用Jenkins遇到的问题
- LeetCode(100):相同的树
- CentOS YUM 安装 TOMCAT6
- excel的小bug
- css实现常用的两栏三栏布局
- JDK和Eclipse的下载路径
- JavaScript的replace方法与正则表达式结合应用讲解
- 散列表碰撞处理、开链法、HashTable散列
- [NOI2018]归程 kruskal重构树
- 更改idea快捷键方式为eclipse风格
- HBase中的TTL与MinVersion的关系