Permalink
Browse files

Added simple api methods for insert/swap/delete methods

  • Loading branch information...
1 parent e575ce2 commit ee9ad9e3956a939a7031b5ec6445105858fa2776 @gmoledina committed Mar 26, 2012
Showing with 27 additions and 3 deletions.
  1. +6 −2 GMGridView/GMGridView.h
  2. +20 −0 GMGridView/GMGridView.m
  3. +1 −1 GMGridView/GMGridView.xcodeproj/project.pbxproj
View
8 GMGridView/GMGridView.h
@@ -82,7 +82,7 @@ typedef enum
@property (nonatomic) NSInteger itemSpacing; // Default is 10
@property (nonatomic) BOOL centerGrid; // Default is YES
@property (nonatomic) UIEdgeInsets minEdgeInsets; // Default is (5, 5, 5, 5)
-@property (nonatomic) CFTimeInterval minimumPressDuration; // Default is 0.2; if set to 0, the scrollView will not be scrollable
+@property (nonatomic) CFTimeInterval minimumPressDuration; // Default is 0.2; if set to 0, the view wont be scrollable
@property (nonatomic) BOOL showFullSizeViewWithAlphaWhenTransforming; // Default is YES - not working right now
@property (nonatomic, readonly) UIScrollView *scrollView __attribute__((deprecated)); // The grid now inherits directly from UIScrollView
@@ -92,13 +92,17 @@ typedef enum
- (GMGridViewCell *)dequeueReusableCellWithIdentifier:(NSString *)identifier;
// Cells
-- (GMGridViewCell *)cellForItemAtIndex:(NSInteger)position; // Might return nil if cell not loaded for the specific index
+- (GMGridViewCell *)cellForItemAtIndex:(NSInteger)position; // Might return nil if cell not loaded yet
// Actions
- (void)reloadData;
+- (void)insertObjectAtIndex:(NSInteger)index animated:(BOOL)animated;
- (void)insertObjectAtIndex:(NSInteger)index withAnimation:(GMGridViewItemAnimation)animation;
+- (void)removeObjectAtIndex:(NSInteger)index animated:(BOOL)animated;
- (void)removeObjectAtIndex:(NSInteger)index withAnimation:(GMGridViewItemAnimation)animation;
+- (void)reloadObjectAtIndex:(NSInteger)index animated:(BOOL)animated;
- (void)reloadObjectAtIndex:(NSInteger)index withAnimation:(GMGridViewItemAnimation)animation;
+- (void)swapObjectAtIndex:(NSInteger)index1 withObjectAtIndex:(NSInteger)index2 animated:(BOOL)animated;
- (void)swapObjectAtIndex:(NSInteger)index1 withObjectAtIndex:(NSInteger)index2 withAnimation:(GMGridViewItemAnimation)animation;
- (void)scrollToObjectAtIndex:(NSInteger)index atScrollPosition:(GMGridViewScrollPosition)scrollPosition animated:(BOOL)animated;
View
20 GMGridView/GMGridView.m
@@ -1491,6 +1491,11 @@ - (void)reloadData
[self setNeedsLayout];
}
+- (void)reloadObjectAtIndex:(NSInteger)index animated:(BOOL)animated
+{
+ [self reloadObjectAtIndex:index withAnimation:animated ? GMGridViewItemAnimationScroll : GMGridViewItemAnimationNone];
+}
+
- (void)reloadObjectAtIndex:(NSInteger)index withAnimation:(GMGridViewItemAnimation)animation
{
NSAssert((index >= 0 && index < _numberTotalItems), @"Invalid index");
@@ -1569,6 +1574,11 @@ - (void)scrollToObjectAtIndex:(NSInteger)index atScrollPosition:(GMGridViewScrol
];
}
+- (void)insertObjectAtIndex:(NSInteger)index animated:(BOOL)animated
+{
+ [self insertObjectAtIndex:index withAnimation: animated ? GMGridViewItemAnimationScroll : GMGridViewItemAnimationNone];
+}
+
- (void)insertObjectAtIndex:(NSInteger)index withAnimation:(GMGridViewItemAnimation)animation
{
NSAssert((index >= 0 && index <= _numberTotalItems), @"Invalid index specified");
@@ -1613,6 +1623,11 @@ - (void)insertObjectAtIndex:(NSInteger)index withAnimation:(GMGridViewItemAnimat
[self setSubviewsCacheAsInvalid];
}
+- (void)removeObjectAtIndex:(NSInteger)index animated:(BOOL)animated
+{
+ [self removeObjectAtIndex:index withAnimation:GMGridViewItemAnimationNone];
+}
+
- (void)removeObjectAtIndex:(NSInteger)index withAnimation:(GMGridViewItemAnimation)animation
{
NSAssert((index >= 0 && index < _numberTotalItems), @"Invalid index specified");
@@ -1656,6 +1671,11 @@ - (void)removeObjectAtIndex:(NSInteger)index withAnimation:(GMGridViewItemAnimat
[self setSubviewsCacheAsInvalid];
}
+- (void)swapObjectAtIndex:(NSInteger)index1 withObjectAtIndex:(NSInteger)index2 animated:(BOOL)animated
+{
+ [self swapObjectAtIndex:index1 withObjectAtIndex:index2 withAnimation:animated ? GMGridViewItemAnimationScroll : GMGridViewItemAnimationNone];
+}
+
- (void)swapObjectAtIndex:(NSInteger)index1 withObjectAtIndex:(NSInteger)index2 withAnimation:(GMGridViewItemAnimation)animation
{
NSAssert((index1 >= 0 && index1 < _numberTotalItems), @"Invalid index1 specified");
View
2 GMGridView/GMGridView.xcodeproj/project.pbxproj
@@ -107,8 +107,8 @@
78509336149FAC61000787E4 /* GMGridView.h */,
78509337149FAC61000787E4 /* GMGridView.m */,
78509338149FAC61000787E4 /* GMGridViewCell.h */,
- 78509339149FAC61000787E4 /* GMGridViewCell.m */,
7850933A149FAC61000787E4 /* GMGridViewCell+Extended.h */,
+ 78509339149FAC61000787E4 /* GMGridViewCell.m */,
7850933B149FAC61000787E4 /* GMGridViewLayoutStrategies.h */,
7850933C149FAC61000787E4 /* GMGridViewLayoutStrategies.m */,
);

0 comments on commit ee9ad9e

Please sign in to comment.