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

#defines for use with feature obj_arc + protocol for more MVC-like behavior #25

Open
wants to merge 1 commit 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
5 changes: 5 additions & 0 deletions Classes/DemoTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@

#import "DemoTableViewController.h"

@interface DemoTableViewController () <PullRefreshTableViewDelegate>

@implementation DemoTableViewController

- (void)viewDidLoad {
[super viewDidLoad];
self.refreshDelegate = self;

self.title = @"Pull to Refresh";
items = [[NSMutableArray alloc] initWithObjects:@"What time is it?", nil];
Expand Down Expand Up @@ -40,6 +42,9 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
return cell;
}

#pragma mark - PullRefreshTableViewDelegate implementation
#pragma mark @required

- (void)refresh {
[self performSelector:@selector(addItem) withObject:nil afterDelay:2.0];
}
Expand Down
31 changes: 26 additions & 5 deletions Classes/PullRefreshTableViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@

#import <UIKit/UIKit.h>

@protocol PullRefreshTableViewDelegate
- (void)refresh;
@end

@interface PullRefreshTableViewController : UITableViewController {
UIView *refreshHeaderView;
Expand All @@ -42,10 +45,29 @@
NSString *textLoading;
}

@property (nonatomic, retain) UIView *refreshHeaderView;
@property (nonatomic, retain) UILabel *refreshLabel;
@property (nonatomic, retain) UIImageView *refreshArrow;
@property (nonatomic, retain) UIActivityIndicatorView *refreshSpinner;
#ifndef PTR_STRONG
#if __has_feature(objc_arc)
#define PTR_STRONG strong
#else
#define PTR_STRONG retain
#endif
#endif

#ifndef PTR_WEAK
#if __has_feature(objc_arc_weak)
#define PTR_WEAK weak
#elif __has_feature(objc_arc)
#define PTR_WEAK unsafe_unretained
#else
#define PTR_WEAK assign
#endif
#endif

@property (nonatomic, PTR_WEAK) id<PullRefreshTableViewDelegate> refreshDelegate;
@property (nonatomic, PTR_STRONG) UIView *refreshHeaderView;
@property (nonatomic, PTR_STRONG) UILabel *refreshLabel;
@property (nonatomic, PTR_STRONG) UIImageView *refreshArrow;
@property (nonatomic, PTR_STRONG) UIActivityIndicatorView *refreshSpinner;
@property (nonatomic, copy) NSString *textPull;
@property (nonatomic, copy) NSString *textRelease;
@property (nonatomic, copy) NSString *textLoading;
Expand All @@ -54,6 +76,5 @@
- (void)addPullToRefreshHeader;
- (void)startLoading;
- (void)stopLoading;
- (void)refresh;

@end
14 changes: 9 additions & 5 deletions Classes/PullRefreshTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

@implementation PullRefreshTableViewController

@synthesize textPull, textRelease, textLoading, refreshHeaderView, refreshLabel, refreshArrow, refreshSpinner;
@synthesize textPull, textRelease, textLoading, refreshDelegate, refreshHeaderView, refreshLabel, refreshArrow, refreshSpinner;

- (id)initWithStyle:(UITableViewStyle)style {
self = [super initWithStyle:style];
Expand Down Expand Up @@ -67,9 +67,9 @@ - (void)viewDidLoad {
}

- (void)setupStrings{
textPull = [[NSString alloc] initWithString:@"Pull down to refresh..."];
textRelease = [[NSString alloc] initWithString:@"Release to refresh..."];
textLoading = [[NSString alloc] initWithString:@"Loading..."];
textPull = NSLocalizedString(@"Pull down to refresh...", nil);
textRelease = NSLocalizedString(@"Release to refresh...", nil);
textLoading = NSLocalizedString(@"Loading...", nil);
}

- (void)addPullToRefreshHeader {
Expand Down Expand Up @@ -145,7 +145,7 @@ - (void)startLoading {
}];

// Refresh action!
[self refresh];
[self.refreshDelegate refresh];
}

- (void)stopLoading {
Expand All @@ -168,12 +168,15 @@ - (void)stopLoadingComplete {
[refreshSpinner stopAnimating];
}

/*
- (void)refresh {
// This is just a demo. Override this method with your custom reload action.
// Don't forget to call stopLoading at the end.
[self performSelector:@selector(stopLoading) withObject:nil afterDelay:2.0];
}
*/

#if !__has_feature(objc_arc)
- (void)dealloc {
[refreshHeaderView release];
[refreshLabel release];
Expand All @@ -184,5 +187,6 @@ - (void)dealloc {
[textLoading release];
[super dealloc];
}
#endif

@end