Skip to content

Commit

Permalink
Use UIRefreshControl on iOS6
Browse files Browse the repository at this point in the history
  • Loading branch information
robertpanzer committed Sep 14, 2012
1 parent 4bcaa66 commit d0fec99
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 10 deletions.
54 changes: 44 additions & 10 deletions Github To Go/PullToRefreshTableViewController.m
Expand Up @@ -7,7 +7,7 @@
//

#import "PullToRefreshTableViewController.h"

#import <CoreText/CoreText.h>


@implementation ReloadLabel
Expand Down Expand Up @@ -65,6 +65,7 @@ -(void)stopActivity {

@interface PullToRefreshTableViewController ()

@property(nonatomic) BOOL useRefreshControl;
@end

@implementation PullToRefreshTableViewController
Expand All @@ -73,18 +74,43 @@ @implementation PullToRefreshTableViewController
@synthesize reloadPossible;
@synthesize isReloading;

-(void)viewWillAppear:(BOOL)animated {
if (self.reloadLabel == nil) {
@class UIRefreshControl;

-(void) viewDidLoad {
[super viewDidLoad];
Class refreshControlClass = NSClassFromString(@"UIRefreshControl");

if (refreshControlClass != NULL) {
self.useRefreshControl = YES;
// New iOS 6 Refresh Control
id refreshControl = [[refreshControlClass alloc] init];
//TODO: Remove id cast once iOS6 is minimum requirement
[self setRefreshControl:refreshControl];
NSDictionary *dict =[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor blackColor], kCTForegroundColorAttributeName,
nil];

NSMutableAttributedString *title = [[NSMutableAttributedString alloc] initWithString:@"Pull to refresh" attributes:dict];

[refreshControl setAttributedTitle:title];
[refreshControl addTarget:self action:@selector(reload:) forControlEvents:UIControlEventValueChanged];
} else {
self.reloadLabel = [[ReloadLabel alloc] initWithFrame:CGRectMake(0.0f, -40.0f, self.tableView.frame.size.width, 40.0f)];
[self.tableView addSubview:self.reloadLabel];

}
[self.tableView.panGestureRecognizer addTarget:self action:@selector(swiped:)];
}

-(void)viewWillAppear:(BOOL)animated {
if (!self.useRefreshControl) {
[self.tableView.panGestureRecognizer addTarget:self action:@selector(swiped:)];
}

}

-(void)viewWillDisappear:(BOOL)animated {
[self.tableView.panGestureRecognizer removeTarget:self action:@selector(swiped:)];
if (!self.useRefreshControl){
[self.tableView.panGestureRecognizer removeTarget:self action:@selector(swiped:)];
}
}

-(void) swiped:(UIPanGestureRecognizer*)recognizer {
Expand Down Expand Up @@ -120,6 +146,10 @@ -(void) swiped:(UIPanGestureRecognizer*)recognizer {
}
}

-(void)reload:(id)sender {
[self reload];
}

-(void)reload {}

-(void)willReload {
Expand All @@ -128,11 +158,15 @@ -(void)willReload {
}

-(void)reloadDidFinish {
if (self.isReloading) {
[self.tableView setContentOffset:CGPointMake(0.0f, 0.0f) animated:YES];
if (self.useRefreshControl) {
[self.refreshControl endRefreshing];
} else {
if (self.isReloading) {
[self.tableView setContentOffset:CGPointMake(0.0f, 0.0f) animated:YES];
}
self.isReloading = NO;
[self.reloadLabel stopActivity];
}
self.isReloading = NO;
[self.reloadLabel stopActivity];
}

@end
4 changes: 4 additions & 0 deletions Hub To Go.xcodeproj/project.pbxproj
Expand Up @@ -81,6 +81,7 @@
94C6566D15025FAD00E85813 /* UITableViewCell+GithubEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 94C6566C15025FAD00E85813 /* UITableViewCell+GithubEvent.m */; };
94C656711503727D00E85813 /* UITableViewCell+Person.m in Sources */ = {isa = PBXBuildFile; fileRef = 94C656701503727D00E85813 /* UITableViewCell+Person.m */; };
94C8AE74160385900026FD9E /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 94C8AE73160385900026FD9E /* Default-568h@2x.png */; };
94C8AE7616038C540026FD9E /* CoreText.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 94C8AE7516038C540026FD9E /* CoreText.framework */; };
94CC3C3B1523B31B00F4B25B /* PersonListTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 94CC3C391523B31B00F4B25B /* PersonListTableViewController.m */; };
94CC3C3C1523B31B00F4B25B /* PersonListTableViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 94CC3C3A1523B31B00F4B25B /* PersonListTableViewController.xib */; };
94CCEDF815951AF700D5D810 /* EventRootViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 94CCEDF715951AF700D5D810 /* EventRootViewController.m */; };
Expand Down Expand Up @@ -229,6 +230,7 @@
94C6566F1503727D00E85813 /* UITableViewCell+Person.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UITableViewCell+Person.h"; sourceTree = "<group>"; };
94C656701503727D00E85813 /* UITableViewCell+Person.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UITableViewCell+Person.m"; sourceTree = "<group>"; };
94C8AE73160385900026FD9E /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = "<group>"; };
94C8AE7516038C540026FD9E /* CoreText.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreText.framework; path = System/Library/Frameworks/CoreText.framework; sourceTree = SDKROOT; };
94CC3C381523B31B00F4B25B /* PersonListTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PersonListTableViewController.h; sourceTree = "<group>"; };
94CC3C391523B31B00F4B25B /* PersonListTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PersonListTableViewController.m; sourceTree = "<group>"; };
94CC3C3A1523B31B00F4B25B /* PersonListTableViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = PersonListTableViewController.xib; sourceTree = "<group>"; };
Expand Down Expand Up @@ -266,6 +268,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
94C8AE7616038C540026FD9E /* CoreText.framework in Frameworks */,
940AF862159BAD7200F8A5EB /* MessageUI.framework in Frameworks */,
940AF85F159B7A8A00F8A5EB /* Twitter.framework in Frameworks */,
94C2F9FC158CBEDF0006640F /* QuartzCore.framework in Frameworks */,
Expand Down Expand Up @@ -426,6 +429,7 @@
949FB12414B3327700D3E713 = {
isa = PBXGroup;
children = (
94C8AE7516038C540026FD9E /* CoreText.framework */,
940AF861159BAD7200F8A5EB /* MessageUI.framework */,
940AF85E159B7A8A00F8A5EB /* Twitter.framework */,
94C2F9FB158CBEDF0006640F /* QuartzCore.framework */,
Expand Down

0 comments on commit d0fec99

Please sign in to comment.