Permalink
Browse files

Considerable Stability Improvements

  • Loading branch information...
1 parent 0be87c3 commit 351c1bb28c808391b40d5d1cdecd652d0152b0c4 Frederic Jacobs committed Jan 27, 2012
View
@@ -32,7 +32,6 @@ - (NSDateFormatter *)dateFormatter {
- (void) viewDidLoad{
appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate initializeArray];
-
}
// When the view appears, update the title and table contents.
@@ -0,0 +1,63 @@
+//
+// EGORefreshTableHeaderView.h
+// Demo
+//
+// Created by Devin Doty on 10/14/09October14.
+// Copyright 2009 enormego. 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 <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;
+
+
+}
+
+@property(nonatomic,assign) id <EGORefreshTableHeaderDelegate> delegate;
+
+- (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
@@ -0,0 +1,260 @@
+//
+// EGORefreshTableHeaderView.m
+// Demo
+//
+// Created by Devin Doty on 10/14/09October14.
+// Copyright 2009 enormego. 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 "EGORefreshTableHeaderView.h"
+
+
+#define TEXT_COLOR [UIColor colorWithRed:87.0/255.0 green:108.0/255.0 blue:137.0/255.0 alpha:1.0]
+#define FLIP_ANIMATION_DURATION 0.18f
+
+
+@interface EGORefreshTableHeaderView (Private)
+- (void)setState:(EGOPullRefreshState)aState;
+@end
+
+@implementation EGORefreshTableHeaderView
+
+@synthesize delegate=_delegate;
+
+
+- (id)initWithFrame:(CGRect)frame {
+ if (self = [super initWithFrame:frame]) {
+
+ self.autoresizingMask = UIViewAutoresizingFlexibleWidth;
+ self.backgroundColor = [UIColor colorWithRed:226.0/255.0 green:231.0/255.0 blue:237.0/255.0 alpha:1.0];
+
+ UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, frame.size.height - 30.0f, self.frame.size.width, 20.0f)];
+ label.autoresizingMask = UIViewAutoresizingFlexibleWidth;
+ label.font = [UIFont systemFontOfSize:12.0f];
+ label.textColor = TEXT_COLOR;
+ label.shadowColor = [UIColor colorWithWhite:0.9f alpha:1.0f];
+ label.shadowOffset = CGSizeMake(0.0f, 1.0f);
+ label.backgroundColor = [UIColor clearColor];
+ label.textAlignment = UITextAlignmentCenter;
+ [self addSubview:label];
+ _lastUpdatedLabel=label;
+ [label release];
+
+ label = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, frame.size.height - 48.0f, self.frame.size.width, 20.0f)];
+ label.autoresizingMask = UIViewAutoresizingFlexibleWidth;
+ label.font = [UIFont boldSystemFontOfSize:13.0f];
+ label.textColor = TEXT_COLOR;
+ label.shadowColor = [UIColor colorWithWhite:0.9f alpha:1.0f];
+ label.shadowOffset = CGSizeMake(0.0f, 1.0f);
+ label.backgroundColor = [UIColor clearColor];
+ label.textAlignment = UITextAlignmentCenter;
+ [self addSubview:label];
+ _statusLabel=label;
+ [label release];
+
+ CALayer *layer = [CALayer layer];
+ layer.frame = CGRectMake(25.0f, frame.size.height - 65.0f, 30.0f, 55.0f);
+ layer.contentsGravity = kCAGravityResizeAspect;
+ layer.contents = (id)[UIImage imageNamed:@"blackArrow.png"].CGImage;
+
+#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 40000
+ if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
+ layer.contentsScale = [[UIScreen mainScreen] scale];
+ }
+#endif
+
+ [[self layer] addSublayer:layer];
+ _arrowImage=layer;
+
+ UIActivityIndicatorView *view = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
+ view.frame = CGRectMake(25.0f, frame.size.height - 38.0f, 20.0f, 20.0f);
+ [self addSubview:view];
+ _activityView = view;
+ [view release];
+
+
+ [self setState:EGOOPullRefreshNormal];
+
+ }
+
+ return self;
+
+}
+
+
+#pragma mark -
+#pragma mark Setters
+
+- (void)refreshLastUpdatedDate {
+
+ if ([_delegate respondsToSelector:@selector(egoRefreshTableHeaderDataSourceLastUpdated:)]) {
+
+ NSDate *date = [_delegate egoRefreshTableHeaderDataSourceLastUpdated:self];
+
+ NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
+ [formatter setAMSymbol:@"AM"];
+ [formatter setPMSymbol:@"PM"];
+ [formatter setDateFormat:@"MM/dd/yyyy hh:mm:a"];
+ _lastUpdatedLabel.text = [NSString stringWithFormat:@"Last Updated: %@", [formatter stringFromDate:date]];
+ [[NSUserDefaults standardUserDefaults] setObject:_lastUpdatedLabel.text forKey:@"EGORefreshTableView_LastRefresh"];
+ [[NSUserDefaults standardUserDefaults] synchronize];
+ [formatter release];
+
+ } else {
+
+ _lastUpdatedLabel.text = nil;
+
+ }
+
+}
+
+- (void)setState:(EGOPullRefreshState)aState{
+
+ switch (aState) {
+ case EGOOPullRefreshPulling:
+
+ _statusLabel.text = NSLocalizedString(@"Release to refresh...", @"Release to refresh status");
+ [CATransaction begin];
+ [CATransaction setAnimationDuration:FLIP_ANIMATION_DURATION];
+ _arrowImage.transform = CATransform3DMakeRotation((M_PI / 180.0) * 180.0f, 0.0f, 0.0f, 1.0f);
+ [CATransaction commit];
+
+ break;
+ case EGOOPullRefreshNormal:
+
+ if (_state == EGOOPullRefreshPulling) {
+ [CATransaction begin];
+ [CATransaction setAnimationDuration:FLIP_ANIMATION_DURATION];
+ _arrowImage.transform = CATransform3DIdentity;
+ [CATransaction commit];
+ }
+
+ _statusLabel.text = NSLocalizedString(@"Pull down to refresh...", @"Pull down to refresh status");
+ [_activityView stopAnimating];
+ [CATransaction begin];
+ [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];
+ _arrowImage.hidden = NO;
+ _arrowImage.transform = CATransform3DIdentity;
+ [CATransaction commit];
+
+ [self refreshLastUpdatedDate];
+
+ break;
+ case EGOOPullRefreshLoading:
+
+ _statusLabel.text = NSLocalizedString(@"Loading...", @"Loading Status");
+ [_activityView startAnimating];
+ [CATransaction begin];
+ [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];
+ _arrowImage.hidden = YES;
+ [CATransaction commit];
+
+ break;
+ default:
+ break;
+ }
+
+ _state = aState;
+}
+
+
+#pragma mark -
+#pragma mark ScrollView Methods
+
+- (void)egoRefreshScrollViewDidScroll:(UIScrollView *)scrollView {
+
+ if (_state == EGOOPullRefreshLoading) {
+
+ CGFloat offset = MAX(scrollView.contentOffset.y * -1, 0);
+ offset = MIN(offset, 60);
+ scrollView.contentInset = UIEdgeInsetsMake(offset, 0.0f, 0.0f, 0.0f);
+
+ } else if (scrollView.isDragging) {
+
+ BOOL _loading = NO;
+ if ([_delegate respondsToSelector:@selector(egoRefreshTableHeaderDataSourceIsLoading:)]) {
+ _loading = [_delegate egoRefreshTableHeaderDataSourceIsLoading:self];
+ }
+
+ if (_state == EGOOPullRefreshPulling && scrollView.contentOffset.y > -65.0f && scrollView.contentOffset.y < 0.0f && !_loading) {
+ [self setState:EGOOPullRefreshNormal];
+ } else if (_state == EGOOPullRefreshNormal && scrollView.contentOffset.y < -65.0f && !_loading) {
+ [self setState:EGOOPullRefreshPulling];
+ }
+
+ if (scrollView.contentInset.top != 0) {
+ scrollView.contentInset = UIEdgeInsetsZero;
+ }
+
+ }
+
+}
+
+- (void)egoRefreshScrollViewDidEndDragging:(UIScrollView *)scrollView {
+
+ BOOL _loading = NO;
+ if ([_delegate respondsToSelector:@selector(egoRefreshTableHeaderDataSourceIsLoading:)]) {
+ _loading = [_delegate egoRefreshTableHeaderDataSourceIsLoading:self];
+ }
+
+ if (scrollView.contentOffset.y <= - 65.0f && !_loading) {
+
+ if ([_delegate respondsToSelector:@selector(egoRefreshTableHeaderDidTriggerRefresh:)]) {
+ [_delegate egoRefreshTableHeaderDidTriggerRefresh:self];
+ }
+
+ [self setState:EGOOPullRefreshLoading];
+ [UIView beginAnimations:nil context:NULL];
+ [UIView setAnimationDuration:0.2];
+ scrollView.contentInset = UIEdgeInsetsMake(60.0f, 0.0f, 0.0f, 0.0f);
+ [UIView commitAnimations];
+
+ }
+
+}
+
+- (void)egoRefreshScrollViewDataSourceDidFinishedLoading:(UIScrollView *)scrollView {
+
+ [UIView beginAnimations:nil context:NULL];
+ [UIView setAnimationDuration:.3];
+ [scrollView setContentInset:UIEdgeInsetsMake(0.0f, 0.0f, 0.0f, 0.0f)];
+ [UIView commitAnimations];
+
+ [self setState:EGOOPullRefreshNormal];
+
+}
+
+
+#pragma mark -
+#pragma mark Dealloc
+
+- (void)dealloc {
+
+ _delegate=nil;
+ _activityView = nil;
+ _statusLabel = nil;
+ _arrowImage = nil;
+ _lastUpdatedLabel = nil;
+ [super dealloc];
+}
+
+
+@end
@@ -8,40 +8,22 @@
#import <UIKit/UIKit.h>
#import "Show.h"
+#import "EGORefreshTableHeaderView.h"
@class DetailController;
-@interface SecondViewController : UITableViewController{
+@interface SecondViewController : UITableViewController <EGORefreshTableHeaderDelegate>{
IBOutlet UITableView *allShows;
NSMutableArray *shows;
DetailController *detailController;
- UIView *refreshHeaderView;
- UILabel *refreshLabel;
- UIImageView *refreshArrow;
- UIActivityIndicatorView *refreshSpinner;
- BOOL isDragging;
- BOOL isLoading;
- NSString *textPull;
- NSString *textRelease;
- NSString *textLoading;
+ EGORefreshTableHeaderView *_refreshHeaderView;
+ BOOL _reloading;
}
@property (nonatomic, retain, readonly) DetailController *detailController;
@property (nonatomic, retain) NSMutableArray *shows;
-@property (nonatomic, retain) UIView *refreshHeaderView;
-@property (nonatomic, retain) UILabel *refreshLabel;
-@property (nonatomic, retain) UIImageView *refreshArrow;
-@property (nonatomic, retain) UIActivityIndicatorView *refreshSpinner;
-@property (nonatomic, copy) NSString *textPull;
-@property (nonatomic, copy) NSString *textRelease;
-@property (nonatomic, copy) NSString *textLoading;
-
-
-- (void)setupStrings;
-- (void)addPullToRefreshHeader;
-- (void)startLoading;
-- (void)stopLoading;
-- (void)refresh;
+- (void)reloadTableViewDataSource;
+- (void)doneLoadingTableViewData;
@end
Oops, something went wrong.

0 comments on commit 351c1bb

Please sign in to comment.