#import <UIKit/UIKit.h>
#import "PullToRefreshTableView.h"
@interface ChyoViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>{
PullToRefreshTableView * tableView;
NSMutableArray * array; // 数据源
}
@property (nonatomic, retain) PullToRefreshTableView * tableView;
@property (nonatomic, retain) NSMutableArray * array;
- (void)updateThread:(NSString *)returnKey;
- (void)updateTableView;
@end
//
// ChyoViewController.m
// PullToRefresh
//
// Created by hsit on 12-1-30.
// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//
#import "ChyoViewController.h"
@implementation ChyoViewController
@synthesize tableView;
@synthesize array;
- (void)dealloc{
[tableView release];
[array release];
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
array = [[NSMutableArray alloc] init];
tableView = [[PullToRefreshTableView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
[table setContentSize:CGSizeMake(320, 960)];
tableView.delegate = self;
tableView.dataSource = self;
tableView.backgroundColor = [UIColor clearColor];
[self.view addSubview:tableView];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (void)updateThread:(NSString *)returnKey{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
sleep(2);
switch ([returnKey intValue]) {
case k_RETURN_REFRESH:
[array removeAllObjects];
[array addObject:[NSString stringWithFormat:@"%d", [array count] + 1]];
break;
case k_RETURN_LOADMORE:
[array addObject:[NSString stringWithFormat:@"%d", [array count] + 1]];
break;
default:
break;
}
[self performSelectorOnMainThread:@selector(updateTableView) withObject:nil waitUntilDone:NO];
[pool release];
}
- (void)updateTableView{
if ([array count] < 10) {
// 一定要调用本方法,否则下拉/上拖视图的状态不会还原,会一直转菊花
[tableView reloadData:NO];
} else {
// 一定要调用本方法,否则下拉/上拖视图的状态不会还原,会一直转菊花
[tableView reloadData:YES];
}
}
#pragma mark -
#pragma mark Scroll View Delegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
[tableView tableViewDidDragging];
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
NSInteger returnKey = [tableView tableViewDidEndDragging];
// returnKey用来判断执行的拖动是下拉还是上拖,如果数据正在加载,则返回DO_NOTHING
if (returnKey != k_RETURN_DO_NOTHING) {
NSString * key = [NSString stringWithFormat:@"%d", returnKey];
[NSThread detachNewThreadSelector:@selector(updateThread:) toTarget:self withObject:key];
}
}
#pragma mark -
#pragma mark Table View DataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
- (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section{
if ([array count] == 0) {
// 本方法是为了在数据未空时,让“下拉刷新”视图可直接显示,比较直观
tableView.contentInset = UIEdgeInsetsMake(k_STATE_VIEW_HEIGHT, 0, 0, 0);
}
return [array count];
}
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString * identifier = @"cell";
UITableViewCell * cell = [aTableView dequeueReusableCellWithIdentifier:@"cell"];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier] autorelease];
}
NSInteger row = indexPath.row;
cell.textLabel.text = [array objectAtIndex:row];
return cell;
}
@end
分享到:
相关推荐
实现UITableView的下拉刷新和上拉加载更多功能
uiscrollview uitableview 上拉 下拉 刷新
根据自己的需求,修改的上拉刷新及下拉刷新
NULL 博文链接:https://anlulu.iteye.com/blog/1833881
UITableView的下拉上啦刷新,代码非常简洁!
UITableView使用EGOTableViewPullRefresh实现下拉刷新,代码基本都注释了。
swift UICollectionView, UITableView 上拉/下拉刷新源代码,xcode6.1 保证能用,源代码出处(http://code4app.com/ios/Pull-to-refresh-in-Swift/53aa79ce933bf07d628b524b)不过下载下来编译20多处错误,本人已经...
很久之前上传的版本,有bug。 今天把之前的代码稍微调整了一点。 自己测试过没什么问题了。
http://download.csdn.net/detail/zengzhenkun/8544475修改该资源,现在无错误了,支持xCode6.4,IOS8.1,8.2,8.4测试通过
使用EGOTableViewPullRefresh开源项目在IOS中实现UITableView的下拉刷新功能,对源码进行了一些改动,支持中英文显示,刷新时间格式也做了修改
实现了IOS UITableView上拉刷新和下拉加载的功能,可以运用的实际项目中去
*****UITableView下拉刷新demo*****
iosUITableView下拉刷新数据,上拉加载更多数据;加载时显示最后刷新的时间及加载框,加载完成后有声音提示;提示音可自定义。
很好用的iOS 下拉刷新demo,直接加入工程皆可以使用,并且易懂,很容易改成自己的风格
2、创建的UITableView继承UIPullToRefreshTableView,同时支持XIB和动态创建两种方式 @interface UIPullToRefreshTableView : UITableView 3、 创建的UIViewController继承UIPullToRefreshViewController @...
MNMPullToRefresh 是一种将下拉刷新功能添加到 UITableView 顶部的解决方案。 该解决方案基于中介者设计模式 ( )。 'MNMPullToRefreshManager' 充当下拉刷新视图与其容器表视图之间的中介,将视图和滚动管理解耦。...
还是很不错的,看了源代码以后,会对自己uitableview 的定制有新的人士
实现上拉刷新/上拉加载效果,可用于实现显示更多内容(show more)的效果。 编译测试,适用环境:Xcode 4.5, iOS 5.0 以上。
实现基本UITableView的下拉刷新和上拉加载更多的功能
快速集成下拉刷新,上提加载功能,UIScrollView 和UITableView都可以快速添加此功能!