Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extending functionality to handle footer also #17

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.xcworkspace
xcuserdata
build
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,18 @@
//

@class EGORefreshTableHeaderView;
@class EGORefreshTableFooterView;
@interface RootViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource>{
EGORefreshTableHeaderView *refreshHeaderView;
EGORefreshTableFooterView *refreshFooterView;

// Reloading should really be your tableviews model class
// Putting it here for demo purposes
BOOL _reloading;
BOOL _reloadingHeader;
BOOL _reloadingFooter;

// Sample data - do not include in your project
NSMutableArray *_sampleData;
}

@property(assign,getter=isReloading) BOOL reloading;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@

#import "RootViewController.h"
#import "EGORefreshTableHeaderView.h"
#import "EGORefreshTableFooterView.h"

@interface RootViewController (Private)

- (void)dataSourceDidFinishLoadingNewData;
- (float)tableViewHeight;
- (void)repositionRefreshHeaderView;
- (float)endOfTableView:(UIScrollView *)scrollView;

@end

Expand All @@ -41,14 +45,24 @@ @implementation RootViewController

- (void)viewDidLoad {
[super viewDidLoad];


_sampleData = [[NSMutableArray alloc] initWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",nil];
[self.tableView reloadData];
if (refreshHeaderView == nil) {
refreshHeaderView = [[EGORefreshTableHeaderView alloc] initWithFrame:CGRectMake(0.0f, 0.0f - self.tableView.bounds.size.height, 320.0f, self.tableView.bounds.size.height)];
refreshHeaderView.backgroundColor = [UIColor colorWithRed:226.0/255.0 green:231.0/255.0 blue:237.0/255.0 alpha:1.0];
[self.tableView addSubview:refreshHeaderView];
self.tableView.showsVerticalScrollIndicator = YES;
[refreshHeaderView release];
}

if (refreshFooterView == nil) {
refreshFooterView = [[EGORefreshTableFooterView alloc] initWithFrame:CGRectMake(0.0f, [self tableViewHeight], 320.0f, 600.0f)];
refreshFooterView.backgroundColor = [UIColor colorWithRed:226.0/255.0 green:231.0/255.0 blue:237.0/255.0 alpha:1.0];
[self.tableView addSubview:refreshFooterView];
self.tableView.showsVerticalScrollIndicator = YES;
[refreshFooterView release];
}
}


Expand Down Expand Up @@ -102,7 +116,7 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 0;
return _sampleData.count;
}


Expand All @@ -117,7 +131,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
}

// Configure the cell.

cell.textLabel.text = [_sampleData objectAtIndex:indexPath.row];
return cell;
}

Expand Down Expand Up @@ -146,28 +160,23 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
*/


/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/


/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source.
[_sampleData removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[self repositionRefreshHeaderView];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
//else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
}
//}
}
*/


/*
Expand All @@ -194,19 +203,36 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView{
} else if (refreshHeaderView.state == EGOOPullRefreshNormal && scrollView.contentOffset.y < -65.0f && !_reloading) {
[refreshHeaderView setState:EGOOPullRefreshPulling];
}

float endOfTable = [self endOfTableView:scrollView];
if (refreshFooterView.state == EGOOPullRefreshPulling && endOfTable < 0.0f && endOfTable > -65.0f && !_reloading) {
[refreshFooterView setState:EGOOPullRefreshNormal];
} else if (refreshFooterView.state == EGOOPullRefreshNormal && endOfTable < -65.0f && !_reloading) {
[refreshFooterView setState:EGOOPullRefreshPulling];
}
}
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{

if (scrollView.contentOffset.y <= - 65.0f && !_reloading) {
_reloading = YES;
[self reloadTableViewDataSource];
[refreshHeaderView setState:EGOOPullRefreshLoading];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.2];
self.tableView.contentInset = UIEdgeInsetsMake(60.0f, 0.0f, 0.0f, 0.0f);
[UIView commitAnimations];
_reloading = YES;
[self reloadTableViewDataSource];
[refreshHeaderView setState:EGOOPullRefreshLoading];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.2];
self.tableView.contentInset = UIEdgeInsetsMake(60.0f, 0.0f, 0.0f, 0.0f);
[UIView commitAnimations];
}

if ([self endOfTableView:scrollView] <= -65.0f && !_reloading) {
_reloading = YES;
[self reloadTableViewDataSource];
[refreshFooterView setState:EGOOPullRefreshLoading];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.2];
self.tableView.contentInset = UIEdgeInsetsMake(0.0f, 0.0f, 60.0f, 0.0f);
[UIView commitAnimations];
}
}

Expand All @@ -219,15 +245,37 @@ - (void)dataSourceDidFinishLoadingNewData{
[self.tableView setContentInset:UIEdgeInsetsMake(0.0f, 0.0f, 0.0f, 0.0f)];
[UIView commitAnimations];

[refreshHeaderView setState:EGOOPullRefreshNormal];
[refreshHeaderView setCurrentDate]; // should check if data reload was successful
if ([refreshHeaderView state] != EGOOPullRefreshNormal) {
[refreshHeaderView setState:EGOOPullRefreshNormal];
[refreshHeaderView setCurrentDate]; // should check if data reload was successful
}

if ([refreshFooterView state] != EGOOPullRefreshNormal) {
[refreshFooterView setState:EGOOPullRefreshNormal];
[refreshFooterView setCurrentDate]; // should check if data reload was successful
}
}

- (float)tableViewHeight {

// return height of table view
return [self.tableView contentSize].height;
}

- (void)repositionRefreshHeaderView {
refreshFooterView.center = CGPointMake(160.0f, [self tableViewHeight] + 300.0f);
}

- (float)endOfTableView:(UIScrollView *)scrollView {
return [self tableViewHeight] - scrollView.bounds.size.height - scrollView.bounds.origin.y;
}

#pragma mark -
#pragma mark Dealloc

- (void)dealloc {
refreshHeaderView = nil;
[_sampleData release];
[super dealloc];
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// EGORefreshTableFooterView.h
// Demo
//
// Created by Zbigniew Kominek on 3/10/11.
// Copyright 2011 Zbigniew Kominek. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

#import <Foundation/Foundation.h>
#import "EGORefreshTableHeaderView.h"


@interface EGORefreshTableFooterView : EGORefreshTableHeaderView {

}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//
// EGORefreshTableFooterView.m
// Demo
//
// Created by Zbigniew Kominek on 3/10/11.
// Copyright 2011 Zbigniew Kominek. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

#import "EGORefreshTableFooterView.h"


@implementation EGORefreshTableFooterView

- (void)setup:(CGRect)frame {
_lastUpdatedLabelFrame = CGRectMake(0.0f, 10.0f, self.frame.size.width, 20.0f);
_statusLabelFrame = CGRectMake(0.0f, 28.0f, self.frame.size.width, 20.0f);
_arrowImageFrame = CGRectMake(25.0f, 10.0f, 30.0f, 55.0f);
_activityViewFrame = CGRectMake(25.0f, 18.0f, 20.0f, 20.0f);

_arrowPullingTransform = CATransform3DMakeRotation((M_PI / 180.0f) * -360.0f, 0.0f, 0.0f, 1.0f);
_arrowNormalTransform = CATransform3DMakeRotation((M_PI / 180.0f) * 180.0f, 0.0f, 0.0f, 1.0f);

_releaseLabelText = NSLocalizedString(@"Release to refresh...", @"Release to refresh status");
_pullingLabelText = NSLocalizedString(@"Pull up to refresh...", @"Pull down to refresh status");
_loadingLabelText = NSLocalizedString(@"Loading...", @"Loading Status");

_userDefaultsKey = @"EGORefreshTableFooterView_LastRefresh";
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,29 @@ typedef enum{

EGOPullRefreshState _state;

@protected
CGRect _lastUpdatedLabelFrame;
CGRect _statusLabelFrame;
CGRect _arrowImageFrame;
CGRect _activityViewFrame;

CATransform3D _arrowPullingTransform;
CATransform3D _arrowNormalTransform;

NSString *_releaseLabelText;
NSString *_pullingLabelText;
NSString *_loadingLabelText;

NSString *_userDefaultsKey;
}

@property(nonatomic,assign) EGOPullRefreshState state;
@property(nonatomic,retain) NSString *releaseLabelText;
@property(nonatomic,retain) NSString *pullingLabelText;
@property(nonatomic,retain) NSString *loadingLabelText;

- (void)setCurrentDate;
- (void)setState:(EGOPullRefreshState)aState;
- (void)setup:(CGRect)frame;

@end
Loading