Skip to content

Commit

Permalink
Merge pull request #37 from Club15CC/15cc-fork
Browse files Browse the repository at this point in the history
Updated source and project for ARC
  • Loading branch information
TimCinel committed Apr 24, 2013
2 parents 5937d2f + 8b15d0c commit 4d01f72
Show file tree
Hide file tree
Showing 22 changed files with 470 additions and 346 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ John Garland github.com/johnnyg (iPad!)
Mark van den Broek github.com/heyhoo
Evan Cordell github.com/ecordell
Greg Combs github.com/grgcombs (Refactor!)
Hari Karam Singh github.com/Club15CC (ARC, CustomPicker)

ActionSheetPicker exists because of these contributors, remember to thank them :)
2 changes: 2 additions & 0 deletions ActionSheetPicker.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

#import "AbstractActionSheetPicker.h"

#import "ActionSheetCustomPicker.h"
#import "ActionSheetCustomPickerDelegate.h"
#import "ActionSheetStringPicker.h"
#import "ActionSheetDatePicker.h"
#import "ActionSheetDistancePicker.h"
Expand Down
4 changes: 2 additions & 2 deletions Pickers/AbstractActionSheetPicker.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@

@interface AbstractActionSheetPicker : NSObject
@property (nonatomic, copy) NSString *title;
@property (nonatomic, retain) UIView *pickerView;
@property (nonatomic, strong) UIView *pickerView;
@property (nonatomic, readonly) CGSize viewSize;
@property (nonatomic, retain) NSMutableArray *customButtons;
@property (nonatomic, strong) NSMutableArray *customButtons;
@property (nonatomic, assign) BOOL hideCancel;
@property (nonatomic, assign) CGRect presentFromRect;

Expand Down
37 changes: 14 additions & 23 deletions Pickers/AbstractActionSheetPicker.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@

@interface AbstractActionSheetPicker()

@property (nonatomic, retain) UIBarButtonItem *barButtonItem;
@property (nonatomic, retain) UIView *containerView;
@property (nonatomic, assign) id target;
@property (nonatomic, strong) UIBarButtonItem *barButtonItem;
@property (nonatomic, strong) UIView *containerView;
@property (nonatomic, unsafe_unretained) id target;
@property (nonatomic, assign) SEL successAction;
@property (nonatomic, assign) SEL cancelAction;
@property (nonatomic, retain) UIActionSheet *actionSheet;
@property (nonatomic, retain) UIPopoverController *popOverController;
@property (nonatomic, retain) NSObject *selfReference;
@property (nonatomic, strong) UIActionSheet *actionSheet;
@property (nonatomic, strong) UIPopoverController *popOverController;
@property (nonatomic, strong) NSObject *selfReference;

- (void)presentPickerForView:(UIView *)aView;
- (void)configureAndPresentPopoverForView:(UIView *)aView;
Expand Down Expand Up @@ -103,15 +103,8 @@ - (void)dealloc {
if ([self.pickerView respondsToSelector:@selector(setDataSource:)])
[self.pickerView performSelector:@selector(setDataSource:) withObject:nil];

self.actionSheet = nil;
self.popOverController = nil;
self.customButtons = nil;
self.pickerView = nil;
self.containerView = nil;
self.barButtonItem = nil;
self.target = nil;

[super dealloc];
}

- (UIView *)configuredPickerView {
Expand All @@ -124,8 +117,12 @@ - (void)notifyTarget:(id)target didSucceedWithAction:(SEL)successAction origin:(
}

- (void)notifyTarget:(id)target didCancelWithAction:(SEL)cancelAction origin:(id)origin {
if (target && cancelAction && [target respondsToSelector:cancelAction])
if (target && cancelAction && [target respondsToSelector:cancelAction]) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
[target performSelector:cancelAction withObject:origin];
#pragma clang diagnostic pop
}
}

#pragma mark - Actions
Expand All @@ -139,7 +136,6 @@ - (void)showActionSheetPicker {
NSAssert(_pickerView != NULL, @"Picker view failed to instantiate, perhaps you have invalid component data.");
[masterView addSubview:_pickerView];
[self presentPickerForView:masterView];
[masterView release];
}

- (IBAction)actionPickerDone:(id)sender {
Expand Down Expand Up @@ -177,7 +173,6 @@ - (void)addCustomButtonWithTitle:(NSString *)title value:(id)value {
value = [NSNumber numberWithInt:0];
NSDictionary *buttonDetails = [[NSDictionary alloc] initWithObjectsAndKeys:title, @"buttonTitle", value, @"buttonValue", nil];
[self.customButtons addObject:buttonDetails];
[buttonDetails release];
}

- (IBAction)customButtonPressed:(id)sender {
Expand All @@ -199,7 +194,7 @@ - (IBAction)customButtonPressed:(id)sender {

- (UIToolbar *)createPickerToolbarWithTitle:(NSString *)title {
CGRect frame = CGRectMake(0, 0, self.viewSize.width, 44);
UIToolbar *pickerToolbar = [[[UIToolbar alloc] initWithFrame:frame] autorelease];
UIToolbar *pickerToolbar = [[UIToolbar alloc] initWithFrame:frame];
pickerToolbar.barStyle = UIBarStyleBlackOpaque;
NSMutableArray *barItems = [[NSMutableArray alloc] init];
NSInteger index = 0;
Expand All @@ -209,7 +204,6 @@ - (UIToolbar *)createPickerToolbarWithTitle:(NSString *)title {
UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithTitle:buttonTitle style:UIBarButtonItemStyleBordered target:self action:@selector(customButtonPressed:)];
button.tag = index;
[barItems addObject:button];
[button release];
index++;
}
if (NO == self.hideCancel) {
Expand All @@ -226,7 +220,6 @@ - (UIToolbar *)createPickerToolbarWithTitle:(NSString *)title {
UIBarButtonItem *doneButton = [self createButtonWithType:UIBarButtonSystemItemDone target:self action:@selector(actionPickerDone:)];
[barItems addObject:doneButton];
[pickerToolbar setItems:barItems animated:YES];
[barItems release];
return pickerToolbar;
}

Expand All @@ -237,13 +230,12 @@ - (UIBarButtonItem *)createToolbarLabelWithTitle:(NSString *)aTitle {
[toolBarItemlabel setFont:[UIFont boldSystemFontOfSize:16]];
[toolBarItemlabel setBackgroundColor:[UIColor clearColor]];
toolBarItemlabel.text = aTitle;
UIBarButtonItem *buttonLabel = [[[UIBarButtonItem alloc]initWithCustomView:toolBarItemlabel] autorelease];
[toolBarItemlabel release];
UIBarButtonItem *buttonLabel = [[UIBarButtonItem alloc]initWithCustomView:toolBarItemlabel];
return buttonLabel;
}

- (UIBarButtonItem *)createButtonWithType:(UIBarButtonSystemItem)type target:(id)target action:(SEL)buttonAction {
return [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:type target:target action:buttonAction] autorelease];
return [[UIBarButtonItem alloc] initWithBarButtonSystemItem:type target:target action:buttonAction];
}

#pragma mark - Utilities and Accessors
Expand Down Expand Up @@ -320,7 +312,6 @@ - (void)configureAndPresentPopoverForView:(UIView *)aView {
viewController.contentSizeForViewInPopover = viewController.view.frame.size;
_popOverController = [[UIPopoverController alloc] initWithContentViewController:viewController];
[self presentPopover:_popOverController];
[viewController release];
}

- (void)presentPopover:(UIPopoverController *)popover {
Expand Down
33 changes: 33 additions & 0 deletions Pickers/ActionSheetCustomPicker.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// ActionSheetPicker.h
// ActionSheetPicker
//
// Created by on 13/03/2012.
// Copyright (c) 2012 Club 15CC. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "AbstractActionSheetPicker.h"
#import "ActionSheetCustomPickerDelegate.h"

@interface ActionSheetCustomPicker : AbstractActionSheetPicker
{
}

/////////////////////////////////////////////////////////////////////////
#pragma mark - Properties
/////////////////////////////////////////////////////////////////////////
@property (nonatomic, strong) id<ActionSheetCustomPickerDelegate> delegate;


/////////////////////////////////////////////////////////////////////////
#pragma mark - Init Methods
/////////////////////////////////////////////////////////////////////////

/** Designated init */
- (id)initWithTitle:(NSString *)title delegate:(id<ActionSheetCustomPickerDelegate>)delegate showCancelButton:(BOOL)showCancelButton origin:(id)origin;

/** Convenience class method for creating an launched */
+ (id)showPickerWithTitle:(NSString *)title delegate:(id<ActionSheetCustomPickerDelegate>)delegate showCancelButton:(BOOL)showCancelButton origin:(id)origin;


@end
83 changes: 83 additions & 0 deletions Pickers/ActionSheetCustomPicker.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//
// ActionSheetPicker.m
// ActionSheetPicker
//
// Created by on 13/03/2012.
// Copyright (c) 2012 Club 15CC. All rights reserved.
//

#import "ActionSheetCustomPicker.h"

@implementation ActionSheetCustomPicker

@synthesize delegate = _delegate;


/////////////////////////////////////////////////////////////////////////
#pragma mark - Init
/////////////////////////////////////////////////////////////////////////

- (id)initWithTitle:(NSString *)title delegate:(id<ActionSheetCustomPickerDelegate>)delegate showCancelButton:(BOOL)showCancelButton origin:(id)origin
{
if (self = [self initWithTarget:nil successAction:nil cancelAction:nil origin:origin]) {;

self.title = title;
self.hideCancel = !showCancelButton;
_delegate = delegate;
}

return self;
}

/////////////////////////////////////////////////////////////////////////

+ (id)showPickerWithTitle:(NSString *)title delegate:(id<ActionSheetCustomPickerDelegate>)delegate showCancelButton:(BOOL)showCancelButton origin:(id)origin
{
ActionSheetCustomPicker *picker = [[ActionSheetCustomPicker alloc] initWithTitle:title delegate:delegate showCancelButton:showCancelButton origin:origin];
[picker showActionSheetPicker];
return picker;
}

/////////////////////////////////////////////////////////////////////////
#pragma mark - AbstractActionSheetPicker fulfilment
/////////////////////////////////////////////////////////////////////////

- (UIView *)configuredPickerView {
CGRect pickerFrame = CGRectMake(0, 40, self.viewSize.width, 216);
UIPickerView *pv = [[UIPickerView alloc] initWithFrame:pickerFrame];

// Default to our delegate being the picker's delegate and datasource
pv.delegate = _delegate;
pv.dataSource = _delegate;
pv.showsSelectionIndicator = YES;

// Allow the delegate to override and set additional configs
if ([_delegate respondsToSelector:@selector(configurePickerView:)]) {
[_delegate configurePickerView:pv];
}
self.pickerView = pv;
return pv;
}

/////////////////////////////////////////////////////////////////////////

- (void)notifyTarget:(id)target didSucceedWithAction:(SEL)successAction origin:(id)origin
{
// Ignore parent args and just notify the delegate
if ([_delegate respondsToSelector:@selector(actionSheetPickerDidSucceed:origin:)]) {
[_delegate actionSheetPickerDidSucceed:self origin:origin];
}
}

/////////////////////////////////////////////////////////////////////////

- (void)notifyTarget:(id)target didCancelWithAction:(SEL)cancelAction origin:(id)origin
{
// Ignore parent args and just notify the delegate
if ([_delegate respondsToSelector:@selector(actionSheetPickerDidCancel:origin:)]) {
[_delegate actionSheetPickerDidCancel:self origin:origin];
}
}


@end
38 changes: 38 additions & 0 deletions Pickers/ActionSheetCustomPickerDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// ActionSheetPickerDelegate.h
// ActionSheetPicker
//
// Created by on 13/03/2012.
// Copyright (c) 2012 Club 15CC. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "AbstractActionSheetPicker.h"

@protocol ActionSheetCustomPickerDelegate <UIPickerViewDelegate, UIPickerViewDataSource>

@optional

/**
Allow the delegate to override default settings for the picker
Allows for instance, ability to set separate delegates and data sources as well as GUI settings on the UIPickerView
If not defined and explicily overridden then this class will be the delegate and dataSource.
*/
- (void)configurePickerView:(UIPickerView *)pickerView;

/**
Success callback
\param actionSheetPicker .pickerView property accesses the picker. Requires a cast to UIView subclass for the picker
\param origin The entity which launched the ActionSheetPicker
*/
- (void)actionSheetPickerDidSucceed:(AbstractActionSheetPicker *)actionSheetPicker origin:(id)origin;

/** Cancel callback. See actionSheetPickerDidSuccess:origin: */
- (void)actionSheetPickerDidCancel:(AbstractActionSheetPicker *)actionSheetPicker origin:(id)origin;


@required

@end
10 changes: 3 additions & 7 deletions Pickers/ActionSheetDatePicker.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

@interface ActionSheetDatePicker()
@property (nonatomic, assign) UIDatePickerMode datePickerMode;
@property (nonatomic, retain) NSDate *selectedDate;
@property (nonatomic, strong) NSDate *selectedDate;
@end

@implementation ActionSheetDatePicker
Expand All @@ -43,7 +43,7 @@ + (id)showPickerWithTitle:(NSString *)title
target:(id)target action:(SEL)action origin:(id)origin {
ActionSheetDatePicker *picker = [[ActionSheetDatePicker alloc] initWithTitle:title datePickerMode:datePickerMode selectedDate:selectedDate target:target action:action origin:origin];
[picker showActionSheetPicker];
return [picker autorelease];
return picker;
}

- (id)initWithTitle:(NSString *)title datePickerMode:(UIDatePickerMode)datePickerMode selectedDate:(NSDate *)selectedDate target:(id)target action:(SEL)action origin:(id)origin {
Expand All @@ -56,14 +56,10 @@ - (id)initWithTitle:(NSString *)title datePickerMode:(UIDatePickerMode)datePicke
return self;
}

- (void)dealloc {
self.selectedDate = nil;
[super dealloc];
}

- (UIView *)configuredPickerView {
CGRect datePickerFrame = CGRectMake(0, 40, self.viewSize.width, 216);
UIDatePicker *datePicker = [[[UIDatePicker alloc] initWithFrame:datePickerFrame] autorelease];
UIDatePicker *datePicker = [[UIDatePicker alloc] initWithFrame:datePickerFrame];
datePicker.datePickerMode = self.datePickerMode;
[datePicker setDate:self.selectedDate animated:NO];
[datePicker addTarget:self action:@selector(eventForDatePicker:) forControlEvents:UIControlEventValueChanged];
Expand Down
13 changes: 4 additions & 9 deletions Pickers/ActionSheetDistancePicker.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
#import <objc/message.h>

@interface ActionSheetDistancePicker()
@property (nonatomic, retain) NSString *bigUnitString;
@property (nonatomic, strong) NSString *bigUnitString;
@property (nonatomic, assign) NSInteger selectedBigUnit;
@property (nonatomic, assign) NSInteger bigUnitMax;
@property (nonatomic, assign) NSInteger bigUnitDigits;
@property (nonatomic, retain) NSString *smallUnitString;
@property (nonatomic, strong) NSString *smallUnitString;
@property (nonatomic, assign) NSInteger selectedSmallUnit;
@property (nonatomic, assign) NSInteger smallUnitMax;
@property (nonatomic, assign) NSInteger smallUnitDigits;
Expand All @@ -52,7 +52,7 @@ @implementation ActionSheetDistancePicker
+ (id)showPickerWithTitle:(NSString *)title bigUnitString:(NSString *)bigUnitString bigUnitMax:(NSInteger)bigUnitMax selectedBigUnit:(NSInteger)selectedBigUnit smallUnitString:(NSString*)smallUnitString smallUnitMax:(NSInteger)smallUnitMax selectedSmallUnit:(NSInteger)selectedSmallUnit target:(id)target action:(SEL)action origin:(id)origin {
ActionSheetDistancePicker *picker = [[ActionSheetDistancePicker alloc] initWithTitle:title bigUnitString:bigUnitString bigUnitMax:bigUnitMax selectedBigUnit:selectedBigUnit smallUnitString:smallUnitString smallUnitMax:smallUnitMax selectedSmallUnit:selectedSmallUnit target:target action:action origin:origin];
[picker showActionSheetPicker];
return [picker autorelease];
return picker;
}

- (id)initWithTitle:(NSString *)title bigUnitString:(NSString *)bigUnitString bigUnitMax:(NSInteger)bigUnitMax selectedBigUnit:(NSInteger)selectedBigUnit smallUnitString:(NSString*)smallUnitString smallUnitMax:(NSInteger)smallUnitMax selectedSmallUnit:(NSInteger)selectedSmallUnit target:(id)target action:(SEL)action origin:(id)origin {
Expand All @@ -71,15 +71,10 @@ - (id)initWithTitle:(NSString *)title bigUnitString:(NSString *)bigUnitString bi
return self;
}

- (void)dealloc {
self.smallUnitString = nil;
self.bigUnitString = nil;
[super dealloc];
}

- (UIView *)configuredPickerView {
CGRect distancePickerFrame = CGRectMake(0, 40, self.viewSize.width, 216);
DistancePickerView *picker = [[[DistancePickerView alloc] initWithFrame:distancePickerFrame] autorelease];
DistancePickerView *picker = [[DistancePickerView alloc] initWithFrame:distancePickerFrame];
picker.delegate = self;
picker.dataSource = self;
picker.showsSelectionIndicator = YES;
Expand Down
Loading

0 comments on commit 4d01f72

Please sign in to comment.