Permalink
Browse files

Fixed issue with table view headers. Switch to protocol to remove dup…

…licate code.
  • Loading branch information...
1 parent a35b029 commit 27042c3498adcba9da8eafb727242744c9d4adfc @devindoty devindoty committed Dec 4, 2010
Showing with 3,680 additions and 401 deletions.
  1. BIN .DS_Store
  2. BIN Demo/.DS_Store
  3. +7 −6 Demo/TableViewPull/Classes/Controller/RootViewController/RootViewController.h
  4. +68 −139 Demo/TableViewPull/Classes/Controller/RootViewController/RootViewController.m
  5. +15 −5 Demo/TableViewPull/Classes/View/RefreshTableHeaderView/EGORefreshTableHeaderView.h
  6. +112 −20 Demo/TableViewPull/Classes/View/RefreshTableHeaderView/EGORefreshTableHeaderView.m
  7. +1,400 −0 Demo/TableViewPull/TableViewPull.xcodeproj/devin.mode1v3
  8. +274 −0 Demo/TableViewPull/TableViewPull.xcodeproj/devin.pbxuser
  9. +2 −2 Demo/TableViewPull/TableViewPull.xcodeproj/project.pbxproj
  10. +18 −0 Demo/TableViewPull/build/Debug-iphonesimulator/TableViewPull.app.dSYM/Contents/Info.plist
  11. BIN ...iewPull/build/Debug-iphonesimulator/TableViewPull.app.dSYM/Contents/Resources/DWARF/TableViewPull
  12. BIN Demo/TableViewPull/build/Debug-iphonesimulator/TableViewPull.app/Info.plist
  13. BIN Demo/TableViewPull/build/Debug-iphonesimulator/TableViewPull.app/MainWindow.nib
  14. +1 −0 Demo/TableViewPull/build/Debug-iphonesimulator/TableViewPull.app/PkgInfo
  15. BIN Demo/TableViewPull/build/Debug-iphonesimulator/TableViewPull.app/RootViewController.nib
  16. BIN Demo/TableViewPull/build/Debug-iphonesimulator/TableViewPull.app/TableViewPull
  17. BIN Demo/TableViewPull/build/Debug-iphonesimulator/TableViewPull.app/blackArrow.png
  18. BIN Demo/TableViewPull/build/Debug-iphonesimulator/TableViewPull.app/blackArrow@2x.png
  19. BIN Demo/TableViewPull/build/Debug-iphonesimulator/TableViewPull.app/blueArrow.png
  20. BIN Demo/TableViewPull/build/Debug-iphonesimulator/TableViewPull.app/blueArrow@2x.png
  21. BIN Demo/TableViewPull/build/Debug-iphonesimulator/TableViewPull.app/grayArrow.png
  22. BIN Demo/TableViewPull/build/Debug-iphonesimulator/TableViewPull.app/grayArrow@2x.png
  23. BIN Demo/TableViewPull/build/Debug-iphonesimulator/TableViewPull.app/whiteArrow.png
  24. BIN Demo/TableViewPull/build/Debug-iphonesimulator/TableViewPull.app/whiteArrow@2x.png
  25. +29 −0 Demo/TableViewPull/build/TableViewPull.build/Debug-iphoneos/TableViewPull.build/TableViewPull.dep
  26. +381 −0 Demo/TableViewPull/build/TableViewPull.build/Debug-iphoneos/TableViewPull.build/build-state.dat
  27. BIN ...l.build/Debug-iphonesimulator/TableViewPull.build/Objects-normal/i386/EGORefreshTableHeaderView.o
  28. BIN ...ViewPull.build/Debug-iphonesimulator/TableViewPull.build/Objects-normal/i386/RootViewController.o
  29. +4 −0 ...ll.build/Debug-iphonesimulator/TableViewPull.build/Objects-normal/i386/TableViewPull.LinkFileList
  30. BIN ...ll.build/Debug-iphonesimulator/TableViewPull.build/Objects-normal/i386/TableViewPullAppDelegate.o
  31. BIN ...ll/build/TableViewPull.build/Debug-iphonesimulator/TableViewPull.build/Objects-normal/i386/main.o
  32. BIN ...bleViewPull.build/Debug-iphonesimulator/TableViewPull.build/TableViewPull-all-target-headers.hmap
  33. BIN .../TableViewPull.build/Debug-iphonesimulator/TableViewPull.build/TableViewPull-generated-files.hmap
  34. BIN ...bleViewPull.build/Debug-iphonesimulator/TableViewPull.build/TableViewPull-own-target-headers.hmap
  35. BIN .../TableViewPull.build/Debug-iphonesimulator/TableViewPull.build/TableViewPull-project-headers.hmap
  36. +20 −0 ...bleViewPull/build/TableViewPull.build/Debug-iphonesimulator/TableViewPull.build/TableViewPull.dep
  37. BIN ...leViewPull/build/TableViewPull.build/Debug-iphonesimulator/TableViewPull.build/TableViewPull.hmap
  38. +20 −0 ...leViewPull/build/TableViewPull.build/Debug-iphonesimulator/TableViewPull.build/TableViewPull~.dep
  39. +453 −0 ...TableViewPull/build/TableViewPull.build/Debug-iphonesimulator/TableViewPull.build/build-state.dat
  40. +454 −0 ...ableViewPull/build/TableViewPull.build/Debug-iphonesimulator/TableViewPull.build/build-state~.dat
  41. +13 −0 Demo/TableViewPull/build/TableViewPull.build/Debug/TableViewPull.build/TableViewPull.dep
  42. +147 −0 Demo/TableViewPull/build/TableViewPull.build/Debug/TableViewPull.build/build-state.dat
  43. BIN Demo/TableViewPull/build/TableViewPull.build/TableViewPull.pbxindex/categories.pbxbtree
  44. BIN Demo/TableViewPull/build/TableViewPull.build/TableViewPull.pbxindex/cdecls.pbxbtree
  45. BIN Demo/TableViewPull/build/TableViewPull.build/TableViewPull.pbxindex/decls.pbxbtree
  46. BIN Demo/TableViewPull/build/TableViewPull.build/TableViewPull.pbxindex/files.pbxbtree
  47. BIN Demo/TableViewPull/build/TableViewPull.build/TableViewPull.pbxindex/imports.pbxbtree
  48. BIN Demo/TableViewPull/build/TableViewPull.build/TableViewPull.pbxindex/pbxindex.header
  49. BIN Demo/TableViewPull/build/TableViewPull.build/TableViewPull.pbxindex/protocols.pbxbtree
  50. BIN Demo/TableViewPull/build/TableViewPull.build/TableViewPull.pbxindex/refs.pbxbtree
  51. BIN Demo/TableViewPull/build/TableViewPull.build/TableViewPull.pbxindex/strings.pbxstrings/control
  52. BIN Demo/TableViewPull/build/TableViewPull.build/TableViewPull.pbxindex/strings.pbxstrings/strings
  53. BIN Demo/TableViewPull/build/TableViewPull.build/TableViewPull.pbxindex/subclasses.pbxbtree
  54. BIN Demo/TableViewPull/build/TableViewPull.build/TableViewPull.pbxindex/symbols0.pbxsymbols
  55. BIN EGOTableViewPullRefresh/.DS_Store
  56. +7 −6 EGOTableViewPullRefresh/Classes/Controller/RootViewController.h
  57. +68 −139 EGOTableViewPullRefresh/Classes/Controller/RootViewController.m
  58. +19 −9 EGOTableViewPullRefresh/Classes/View/EGORefreshTableHeaderView.h
  59. +168 −75 EGOTableViewPullRefresh/Classes/View/EGORefreshTableHeaderView.m
View
BIN .DS_Store
Binary file not shown.
View
Binary file not shown.
@@ -24,17 +24,18 @@
// THE SOFTWARE.
//
-@class EGORefreshTableHeaderView;
-@interface RootViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource>{
- EGORefreshTableHeaderView *refreshHeaderView;
+
+#import "EGORefreshTableHeaderView.h"
+
+@interface RootViewController : UITableViewController <EGORefreshTableHeaderDelegate, UITableViewDelegate, UITableViewDataSource>{
- // Reloading should really be your tableviews model class
+ EGORefreshTableHeaderView *_refreshHeaderView;
+
+ // Reloading var should really be your tableviews datasource
// Putting it here for demo purposes
BOOL _reloading;
}
-@property(assign,getter=isReloading) BOOL reloading;
-
- (void)reloadTableViewDataSource;
- (void)doneLoadingTableViewData;
@end
@@ -25,88 +25,44 @@
//
#import "RootViewController.h"
-#import "EGORefreshTableHeaderView.h"
-
-@interface RootViewController (Private)
-
-- (void)dataSourceDidFinishLoadingNewData;
-
-@end
-
@implementation RootViewController
-@synthesize reloading=_reloading;
-
-
- (void)viewDidLoad {
[super viewDidLoad];
-
- 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 (_refreshHeaderView == nil) {
+
+ EGORefreshTableHeaderView *view = [[EGORefreshTableHeaderView alloc] initWithFrame:CGRectMake(0.0f, 0.0f - self.tableView.bounds.size.height, 320.0f, self.tableView.bounds.size.height)];
+ view.delegate = self;
+ [self.tableView addSubview:view];
+ _refreshHeaderView = view;
+ [view release];
+
}
-}
-
+
+ // update the last update date
+ [view refreshLastUpdatedDate];
-/*
-- (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];
+
}
-*/
-
- // Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
- // Return YES for supported orientations.
return YES;
}
-
-
-- (void)didReceiveMemoryWarning {
- // Releases the view if it doesn't have a superview.
- [super didReceiveMemoryWarning];
-
- // Release any cached data, images, etc that aren't in use.
-}
-
-- (void)viewDidUnload {
- refreshHeaderView=nil;
-}
-#pragma mark Table view methods
+#pragma mark -
+#pragma mark UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return 1;
+ return 10;
}
-
-// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return 0;
+ return 4;
}
-
-// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
@@ -121,113 +77,86 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
return cell;
}
+- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
+
+ return [NSString stringWithFormat:@"Section %i", section];
+
+}
+
+
+#pragma mark -
+#pragma mark Data Source Loading / Reloading Methods
+
- (void)reloadTableViewDataSource{
- // should be calling your tableviews model to reload
+
+ // should be calling your tableviews data source model to reload
// put here just for demo
- [self performSelector:@selector(doneLoadingTableViewData) withObject:nil afterDelay:3.0];
+ _reloading = YES;
+
}
-
- (void)doneLoadingTableViewData{
+
// model should call this when its done loading
- [self dataSourceDidFinishLoadingNewData];
-}
-
-
-/*
-// Override to support row selection in the table view.
-- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
-
- // Navigation logic may go here -- for example, create and push another view controller.
- // AnotherViewController *anotherViewController = [[AnotherViewController alloc] initWithNibName:@"AnotherView" bundle:nil];
- // [self.navigationController pushViewController:anotherViewController animated:YES];
- // [anotherViewController release];
+ _reloading = NO;
+ [_refreshHeaderView egoRefreshScrollViewDataSourceDidFinishedLoading:self.tableView];
+
}
-*/
-/*
-// 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;
-}
-*/
-
+#pragma mark -
+#pragma mark UIScrollViewDelegate Methods
-/*
-// 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.
- [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
- }
- 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.
- }
+- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
+
+ [_refreshHeaderView egoRefreshScrollViewDidScroll:scrollView];
+
}
-*/
-
-/*
-// Override to support rearranging the table view.
-- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
+- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
+
+ [_refreshHeaderView egoRefreshScrollViewDidEndDragging:scrollView];
+
}
-*/
-/*
-// Override to support conditional rearranging of the table view.
-- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
- // Return NO if you do not want the item to be re-orderable.
- return YES;
-}
-*/
-
+#pragma mark -
+#pragma mark EGORefreshTableHeaderDelegate Methods
-- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
+- (void)egoRefreshTableHeaderDidTriggerRefresh:(EGORefreshTableHeaderView*)view{
+
+ [self reloadTableViewDataSource];
+ [self performSelector:@selector(doneLoadingTableViewData) withObject:nil afterDelay:3.0];
- if (scrollView.isDragging) {
- if (refreshHeaderView.state == EGOOPullRefreshPulling && scrollView.contentOffset.y > -65.0f && scrollView.contentOffset.y < 0.0f && !_reloading) {
- [refreshHeaderView setState:EGOOPullRefreshNormal];
- } else if (refreshHeaderView.state == EGOOPullRefreshNormal && scrollView.contentOffset.y < -65.0f && !_reloading) {
- [refreshHeaderView setState:EGOOPullRefreshPulling];
- }
- }
}
-- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
+- (BOOL)egoRefreshTableHeaderDataSourceIsLoading:(EGORefreshTableHeaderView*)view{
+
+ return _reloading; // should return if data source model is reloading
- 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];
- }
}
-- (void)dataSourceDidFinishLoadingNewData{
-
- _reloading = NO;
+- (NSDate*)egoRefreshTableHeaderDataSourceLastUpdated:(EGORefreshTableHeaderView*)view{
- [UIView beginAnimations:nil context:NULL];
- [UIView setAnimationDuration:.3];
- [self.tableView setContentInset:UIEdgeInsetsMake(0.0f, 0.0f, 0.0f, 0.0f)];
- [UIView commitAnimations];
+ return [NSDate date]; // should return date data source was last changed
- [refreshHeaderView setState:EGOOPullRefreshNormal];
- [refreshHeaderView setCurrentDate]; // should check if data reload was successful
}
+
#pragma mark -
-#pragma mark Dealloc
+#pragma mark Memory Management
+
+- (void)didReceiveMemoryWarning {
+ [super didReceiveMemoryWarning];
+}
+
+- (void)viewDidUnload {
+ _refreshHeaderView=nil;
+}
- (void)dealloc {
- refreshHeaderView = nil;
+
+ _refreshHeaderView = nil;
[super dealloc];
}
@@ -27,27 +27,37 @@
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
-
typedef enum{
EGOOPullRefreshPulling = 0,
EGOOPullRefreshNormal,
EGOOPullRefreshLoading,
} EGOPullRefreshState;
+@protocol EGORefreshTableHeaderDelegate;
@interface EGORefreshTableHeaderView : UIView {
+ id _delegate;
+ EGOPullRefreshState _state;
+
UILabel *_lastUpdatedLabel;
UILabel *_statusLabel;
CALayer *_arrowImage;
UIActivityIndicatorView *_activityView;
- EGOPullRefreshState _state;
}
-@property(nonatomic,assign) EGOPullRefreshState state;
+@property(nonatomic,assign) id <EGORefreshTableHeaderDelegate> delegate;
-- (void)setCurrentDate;
-- (void)setState:(EGOPullRefreshState)aState;
+- (void)refreshLastUpdatedDate;
+- (void)egoRefreshScrollViewDidScroll:(UIScrollView *)scrollView;
+- (void)egoRefreshScrollViewDidEndDragging:(UIScrollView *)scrollView;
+- (void)egoRefreshScrollViewDataSourceDidFinishedLoading:(UIScrollView *)scrollView;
@end
+@protocol EGORefreshTableHeaderDelegate
+- (void)egoRefreshTableHeaderDidTriggerRefresh:(EGORefreshTableHeaderView*)view;
+- (BOOL)egoRefreshTableHeaderDataSourceIsLoading:(EGORefreshTableHeaderView*)view;
+@optional
+- (NSDate*)egoRefreshTableHeaderDataSourceLastUpdated:(EGORefreshTableHeaderView*)view;
+@end
Oops, something went wrong.

0 comments on commit 27042c3

Please sign in to comment.