Skip to content

Commit

Permalink
Add initial support for iOS4
Browse files Browse the repository at this point in the history
… while using iOS5 features when possible. (uses weak when available)
There are still some problems with getting the Gesture Recognizers and changing layout strategy doesn't work yet, but it's a start.

Plus, this fixes a missing subclass from NSObject in GMGridViewLayoutStragegyFactory, which works for iOS5 but crashes with runtime problems in NSInvocation in iOS4.
  • Loading branch information
steipete authored and gmoledina committed Dec 12, 2011
1 parent 0aebad8 commit 05d714f
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 31 deletions.
6 changes: 2 additions & 4 deletions GMGridView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 5.0;
IPHONEOS_DEPLOYMENT_TARGET = 4.0;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
};
Expand All @@ -296,7 +296,7 @@
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 5.0;
IPHONEOS_DEPLOYMENT_TARGET = 4.0;
OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1";
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
Expand All @@ -310,7 +310,6 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "GMGridView/GMGridView-Prefix.pch";
INFOPLIST_FILE = "GMGridView/GMGridView-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 5.0;
PRODUCT_NAME = GMGridView;
WRAPPER_EXTENSION = app;
};
Expand All @@ -322,7 +321,6 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "GMGridView/GMGridView-Prefix.pch";
INFOPLIST_FILE = "GMGridView/GMGridView-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 5.0;
PRODUCT_NAME = GMGridView;
WRAPPER_EXTENSION = app;
};
Expand Down
22 changes: 17 additions & 5 deletions GMGridView/API/GMGridView.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@
//

#import <UIKit/UIKit.h>

// use special weak keyword
#if !defined gm_weak && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_5_0
#define gm_weak weak
#define __gm_weak __weak
#define gm_nil(x)
#elif !defined gm_weak
#define gm_weak unsafe_unretained
#define __gm_weak __unsafe_unretained
#define gm_nil(x) x = nil
#endif

#import "GMGridViewCell.h"

@protocol GMGridViewDataSource;
Expand All @@ -52,10 +64,10 @@ typedef enum
}

// Delegates
@property (nonatomic, weak) NSObject<GMGridViewDataSource> *dataSource; // Required
@property (nonatomic, weak) NSObject<GMGridViewActionDelegate> *actionDelegate; // Optional - to get taps callback
@property (nonatomic, weak) NSObject<GMGridViewSortingDelegate> *sortingDelegate; // Optional - to enable sorting
@property (nonatomic, weak) NSObject<GMGridViewTransformationDelegate> *transformDelegate; // Optional - to enable fullsize mode
@property (nonatomic, gm_weak) NSObject<GMGridViewDataSource> *dataSource; // Required
@property (nonatomic, gm_weak) NSObject<GMGridViewActionDelegate> *actionDelegate; // Optional - to get taps callback
@property (nonatomic, gm_weak) NSObject<GMGridViewSortingDelegate> *sortingDelegate; // Optional - to enable sorting
@property (nonatomic, gm_weak) NSObject<GMGridViewTransformationDelegate> *transformDelegate; // Optional - to enable fullsize mode

// Layout Strategy
@property (nonatomic, strong) id<GMGridViewLayoutStrategy> layoutStrategy; // Default is GMGridViewLayoutVerticalStrategy
Expand All @@ -64,7 +76,7 @@ typedef enum
@property (nonatomic, getter=isEditing) BOOL editing; // Default is NO - When set to YES, all gestures are disabled and delete buttons shows up on cells

// Customizing Options
@property (nonatomic, weak) UIView *mainSuperView; // Default is self
@property (nonatomic, gm_weak) UIView *mainSuperView; // Default is self
@property (nonatomic) GMGridViewStyle style; // Default is GMGridViewStyleSwap
@property (nonatomic) NSInteger itemSpacing; // Default is 10
@property (nonatomic) BOOL centerGrid; // Default is YES
Expand Down
16 changes: 13 additions & 3 deletions GMGridView/API/GMGridView.m
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,18 @@ - (id)initWithFrame:(CGRect)frame

////////////////////////
// Gesture dependencies
[_scrollView.panGestureRecognizer setMaximumNumberOfTouches:1];
[_scrollView.panGestureRecognizer requireGestureRecognizerToFail:_sortingPanGesture];
UIPanGestureRecognizer *panGestureRecognizer = nil;
if ([_scrollView respondsToSelector:@selector(panGestureRecognizer)]) { // iOS5 only
panGestureRecognizer = _scrollView.panGestureRecognizer;
}else {
for (UIGestureRecognizer *gestureRecognizer in _scrollView.gestureRecognizers) {
if ([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
panGestureRecognizer = (UIPanGestureRecognizer *) gestureRecognizer;
}
}
}
[panGestureRecognizer setMaximumNumberOfTouches:1];
[panGestureRecognizer requireGestureRecognizerToFail:_sortingPanGesture];

self.layoutStrategy = [GMGridViewLayoutStrategyFactory strategyFromType:GMGridViewLayoutVertical];

Expand Down Expand Up @@ -1000,7 +1010,7 @@ - (GMGridViewCell *)newItemSubViewForPosition:(NSInteger)position
cell.tag = position + kTagOffset;
cell.editing = self.editing;

__weak GMGridView *weakSelf = self;
__gm_weak GMGridView *weakSelf = self;

cell.deleteBlock = ^(GMGridViewCell *cell)
{
Expand Down
3 changes: 2 additions & 1 deletion GMGridView/API/GMGridViewCell+Extended.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
//

#import <Foundation/Foundation.h>
#import "GMGridView.h"
#import "GMGridViewCell.h"

typedef void (^GMGridViewCellDeleteBlock)(GMGridViewCell*);
Expand All @@ -51,7 +52,7 @@ typedef void (^GMGridViewCellDeleteBlock)(GMGridViewCell*);
@property (nonatomic, copy) GMGridViewCellDeleteBlock deleteBlock;

@property (nonatomic, assign) UIViewAutoresizing defaultFullsizeViewResizingMask;
@property (nonatomic, weak) UIButton *deleteButton;
@property (nonatomic, gm_weak) UIButton *deleteButton;


- (void)prepareForReuse;
Expand Down
2 changes: 1 addition & 1 deletion GMGridView/API/GMGridViewLayoutStrategies.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ typedef enum {
#pragma mark - Strategy Factory
//////////////////////////////////////////////////////////////

@interface GMGridViewLayoutStrategyFactory
@interface GMGridViewLayoutStrategyFactory : NSObject

+ (id<GMGridViewLayoutStrategy>)strategyFromType:(GMGridViewLayoutStrategyType)type;

Expand Down
30 changes: 18 additions & 12 deletions GMGridView/Demo1ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

@interface Demo1ViewController () <GMGridViewDataSource, GMGridViewSortingDelegate, GMGridViewTransformationDelegate, GMGridViewActionDelegate>
{
__weak GMGridView *_gmGridView;
__gm_weak GMGridView *_gmGridView;
UINavigationController *_optionsNav;
UIPopoverController *_optionsPopOver;

Expand Down Expand Up @@ -62,15 +62,21 @@ - (id)init
space2.width = 10;

UIBarButtonItem *refreshButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refreshItem)];

self.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects:addButton, space, removeButton, space2, refreshButton, nil];

if ([self.navigationItem respondsToSelector:@selector(leftBarButtonItems)]) {
self.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects:addButton, space, removeButton, space2, refreshButton, nil];
}else {
self.navigationItem.leftBarButtonItem = addButton;
}

UIBarButtonItem *optionsButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:self action:@selector(presentOptions:)];

self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:optionsButton, nil];
if ([self.navigationItem respondsToSelector:@selector(rightBarButtonItems)]) {
self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:optionsButton, nil];
}else {
self.navigationItem.rightBarButtonItem = optionsButton;
}


_data = [[NSMutableArray alloc] init];

for (int i = 0; i < NUMBER_ITEMS_ON_LOAD; i ++)
Expand Down Expand Up @@ -108,7 +114,7 @@ - (void)loadView
_gmGridView.sortingDelegate = self;
_gmGridView.transformDelegate = self;
_gmGridView.dataSource = self;

UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeInfoDark];
infoButton.frame = CGRectMake(self.view.bounds.size.width - 40,
self.view.bounds.size.height - 40,
Expand All @@ -117,19 +123,19 @@ - (void)loadView
infoButton.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin;
[infoButton addTarget:self action:@selector(presentInfo) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:infoButton];


OptionsViewController *optionsController = [[OptionsViewController alloc] init];
optionsController.gridView = gmGridView;
optionsController.contentSizeForViewInPopover = CGSizeMake(400, 500);

_optionsNav = [[UINavigationController alloc] initWithRootViewController:optionsController];

if (INTERFACE_IS_PHONE)
{
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(optionsDoneAction)];
optionsController.navigationItem.rightBarButtonItem = doneButton;
}
if (INTERFACE_IS_PHONE)
{
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(optionsDoneAction)];
optionsController.navigationItem.rightBarButtonItem = doneButton;
}
}

- (void)viewDidLoad
Expand Down
8 changes: 4 additions & 4 deletions GMGridView/Demo2ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@

@interface Demo2ViewController () <GMGridViewDataSource, GMGridViewSortingDelegate, GMGridViewTransformationDelegate>
{
__weak GMGridView *_gmGridView1;
__weak GMGridView *_gmGridView2;
__gm_weak GMGridView *_gmGridView1;
__gm_weak GMGridView *_gmGridView2;

__weak UIButton *_buttonOptionsGrid1;
__weak UIButton *_buttonOptionsGrid2;
__gm_weak UIButton *_buttonOptionsGrid1;
__gm_weak UIButton *_buttonOptionsGrid2;

UIPopoverController *_popOverController;
UIViewController *_optionsController1;
Expand Down
2 changes: 1 addition & 1 deletion GMGridView/OptionsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

@interface OptionsViewController () <UITableViewDelegate, UITableViewDataSource, UIPickerViewDelegate, UIPickerViewDataSource>
{
__weak UITableView *_tableView;
__gm_weak UITableView *_tableView;
}

- (void)editingSwitchChanged:(UISwitch *)control;
Expand Down

0 comments on commit 05d714f

Please sign in to comment.