Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add initial support for iOS4

… 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...
commit 05d714f14189d70da7b1043ccffd1cc2912bb8e5 1 parent 0aebad8
@steipete steipete authored committed
View
6 GMGridView.xcodeproj/project.pbxproj
@@ -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";
};
@@ -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";
@@ -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;
};
@@ -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;
};
View
22 GMGridView/API/GMGridView.h
@@ -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;
@@ -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
@@ -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
View
16 GMGridView/API/GMGridView.m
@@ -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];
@@ -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)
{
View
3  GMGridView/API/GMGridViewCell+Extended.h
@@ -27,6 +27,7 @@
//
#import <Foundation/Foundation.h>
+#import "GMGridView.h"
#import "GMGridViewCell.h"
typedef void (^GMGridViewCellDeleteBlock)(GMGridViewCell*);
@@ -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;
View
2  GMGridView/API/GMGridViewLayoutStrategies.h
@@ -46,7 +46,7 @@ typedef enum {
#pragma mark - Strategy Factory
//////////////////////////////////////////////////////////////
-@interface GMGridViewLayoutStrategyFactory
+@interface GMGridViewLayoutStrategyFactory : NSObject
+ (id<GMGridViewLayoutStrategy>)strategyFromType:(GMGridViewLayoutStrategyType)type;
View
30 GMGridView/Demo1ViewController.m
@@ -20,7 +20,7 @@
@interface Demo1ViewController () <GMGridViewDataSource, GMGridViewSortingDelegate, GMGridViewTransformationDelegate, GMGridViewActionDelegate>
{
- __weak GMGridView *_gmGridView;
+ __gm_weak GMGridView *_gmGridView;
UINavigationController *_optionsNav;
UIPopoverController *_optionsPopOver;
@@ -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 ++)
@@ -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,
@@ -117,7 +123,7 @@ - (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;
@@ -125,11 +131,11 @@ - (void)loadView
_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
View
8 GMGridView/Demo2ViewController.m
@@ -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;
View
2  GMGridView/OptionsViewController.m
@@ -54,7 +54,7 @@
@interface OptionsViewController () <UITableViewDelegate, UITableViewDataSource, UIPickerViewDelegate, UIPickerViewDataSource>
{
- __weak UITableView *_tableView;
+ __gm_weak UITableView *_tableView;
}
- (void)editingSwitchChanged:(UISwitch *)control;
Please sign in to comment.
Something went wrong with that request. Please try again.