Skip to content

Commit

Permalink
- Delegate Example added
Browse files Browse the repository at this point in the history
  • Loading branch information
uzysjung committed Jun 1, 2013
1 parent 47a964a commit 9e139ef
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 45 deletions.
44 changes: 32 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ UzysGridView is simple GridView iOS Component which you can easily change positi
**UzysGridView features:**
* you can move the cell position to other page.
* Unlike of spring board, page was not seperated. cells stand in a row.
* Portrait & LandScape supported
* Portrait & LandScape supported

#####+ I made this long time ago when iOS version wass 3.xx ~ 4.xx. at that time, I was a beginner at iOS. but it works :)
#####+ I made this long time ago when iOS version was 3.xx ~ 4.xx. at that time, I was a beginner. but it works :)


## Installation
Expand All @@ -24,37 +24,57 @@ Copy over the files 'UzysGridView' folder to your project folder

### Initialize
``` objective-c
gridView = [[UzysGridView alloc] initWithFrame:self.view.frame numOfRow:3 numOfColumns:2 cellMargin:2];
gridView.delegate = self;
gridView.dataSource = self;
[self.view addSubview:gridView];
_gridView = [[UzysGridView alloc] initWithFrame:self.view.frame numOfRow:3 numOfColumns:2 cellMargin:2];
_gridView.delegate = self;
_gridView.dataSource = self;
[self.view addSubview:_gridView];
````
### DataSource &amp Delegate
### Reload
``` objective-c
[_gridView reloadData];
````
### DataSource & Delegate
``` objective-c
#pragma mark- UzysGridViewDataSource

-(NSInteger) numberOfCellsInGridView:(UzysGridView *)gridview {
return [test_arr count];
return [_test_arr count];
}
-(UzysGridViewCell *)gridView:(UzysGridView *)gridview cellAtIndex:(NSUInteger)index
{
UzysGridViewCustomCell *cell = [[[UzysGridViewCustomCell alloc] initWithFrame:CGRectNull] autorelease];
cell.textLabel.text = [test_arr objectAtIndex:index];
cell.textLabel.text = [NSString stringWithFormat:@"Cell %d", index];
cell.textLabel.text = [_test_arr objectAtIndex:index];
cell.textLabel.text = [NSString stringWithFormat:@"%@", _test_arr[index]];
cell.backgroundView.backgroundColor = [UIColor scrollViewTexturedBackgroundColor];

if(index ==0)
cell.deletable = NO;
return cell;
}

- (void)gridView:(UzysGridView *)gridview moveAtIndex:(NSUInteger)fromindex toIndex:(NSUInteger)toIndex
{
NSMutableDictionary *Temp = [[_test_arr objectAtIndex:fromindex] retain];

[_test_arr removeObjectAtIndex:fromindex];
[_test_arr insertObject:Temp atIndex:toIndex];
[Temp release];
}

-(void) gridView:(UzysGridView *)gridview deleteAtIndex:(NSUInteger)index
{
[test_arr removeObjectAtIndex:index];
[_test_arr removeObjectAtIndex:index];
}

#pragma mark- UzysGridViewDelegate
-(void) gridView:(UzysGridView *)gridView changedPageIndex:(NSUInteger)index
{
NSLog(@"Page : %d",index);
}
-(void) gridView:(UzysGridView *)gridView didSelectCell:(UzysGridViewCell *)cell atIndex:(NSUInteger)index
{
NSLog(@"Cell index %d",index);
}


````
Expand Down
12 changes: 11 additions & 1 deletion UzysGridView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
C0138E651467AB5200646E0E /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0420;
LastUpgradeCheck = 0460;
ORGANIZATIONNAME = NCSoft;
};
buildConfigurationList = C0138E681467AB5200646E0E /* Build configuration list for PBXProject "UzysGridView" */;
Expand Down Expand Up @@ -241,6 +241,10 @@
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
GCC_C_LANGUAGE_STANDARD = gnu99;
Expand All @@ -254,6 +258,7 @@
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 5.0;
SDKROOT = iphoneos;
Expand All @@ -267,12 +272,17 @@
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 5.0;
OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1";
Expand Down
19 changes: 5 additions & 14 deletions UzysGridView/UzysGridView/UzysGridView.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

@class UzysGridView;

#pragma - UzysGridViewDataSource
#pragma mark - UzysGridViewDataSource
@protocol UzysGridViewDataSource<NSObject>
-(NSInteger) numberOfCellsInGridView:(UzysGridView *)gridview;
-(UzysGridViewCell *)gridView:(UzysGridView *)gridview cellAtIndex:(NSUInteger)index;
Expand All @@ -22,7 +22,7 @@
-(void) gridView:(UzysGridView *)gridview InsertAtIndex:(NSUInteger)index;
@end

#pragma -UzysGridViewDelegate
#pragma mark - UzysGridViewDelegate
@protocol UzysGridViewDelegate<NSObject>
@optional
-(void) gridView:(UzysGridView *)gridView didSelectCell:(UzysGridViewCell *)cell atIndex:(NSUInteger)index;
Expand All @@ -36,7 +36,7 @@
-(void) gridView:(UzysGridView *)gridView TouchCanceled:(UzysGridViewCell *)cell;
@end

#pragma UzysGridViewScrollViewDelegate
#pragma mark - UzysGridViewScrollViewDelegate
@protocol UzysGridViewScrollViewDelegate<NSObject>
@optional
-(void) gridView:(UzysGridView *)gridView scrollViewDidEndDecelerating:(UIScrollView *)scrollView;
Expand All @@ -46,7 +46,7 @@
-(void) gridView:(UzysGridView *)gridView scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView;
@end

#pragma -UzysGridView
#pragma mark - UzysGridView
@interface UzysGridView : UIView <UIScrollViewDelegate,UzysGridViewCellDelegate,UIAlertViewDelegate>
{
UIScrollView *_scrollView;
Expand All @@ -73,14 +73,5 @@
@property (nonatomic, assign) BOOL editable;

- (void) reloadData;
- (id)initWithFrame:(CGRect)frame numOfRow:(NSUInteger)rows numOfColumns:(NSUInteger)columns cellMargin:(NSUInteger)cellMargins;

//Cell Method;
- (void) setCurrentPageIndex:(NSUInteger)currentPageIndex;
- (void) MovePage:(NSInteger)index animated:(BOOL) animate;
- (void)cellWasSelected:(UzysGridViewCell *)cell;
- (void)cellWasDelete:(UzysGridViewCell *)cell;
- (void) CellSetPosition:(UzysGridViewCell *) cell;
- (void)editableAnimation;
- (NSInteger) CellCollisionDetection:(UzysGridViewCell *) cell;
- (id) initWithFrame:(CGRect)frame numOfRow:(NSUInteger)rows numOfColumns:(NSUInteger)columns cellMargin:(NSUInteger)cellMargins;
@end
15 changes: 12 additions & 3 deletions UzysGridView/UzysGridView/UzysGridView.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,20 @@
#import "UzysGridView.h"

@interface UzysGridView (private)
-(void) InitVariable;
-(void) CellRearrange:(NSInteger) moveIndex with:(NSInteger)targetIndex;
- (void) InitVariable;
- (void) CellRearrange:(NSInteger) moveIndex with:(NSInteger)targetIndex;
- (void) DeleteCell:(NSInteger)index;
- (void) createLayout:(BOOL)isVariable;
- (void) LoadTotalView ;

//Cell Method;
- (void) setCurrentPageIndex:(NSUInteger)currentPageIndex;
- (void) MovePage:(NSInteger)index animated:(BOOL) animate;
- (void) cellWasSelected:(UzysGridViewCell *)cell;
- (void) cellWasDelete:(UzysGridViewCell *)cell;
- (void) CellSetPosition:(UzysGridViewCell *) cell;
- (void) editableAnimation;
- (NSInteger) CellCollisionDetection:(UzysGridViewCell *) cell;
@end

@implementation UzysGridView
Expand Down Expand Up @@ -615,7 +624,7 @@ - (void) MovePage:(NSInteger)index animated:(BOOL) animate

if(animate)
{
[UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationCurveEaseInOut animations:^{_scrollView.contentOffset = move;} completion:^(BOOL finished){
[UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{_scrollView.contentOffset = move;} completion:^(BOOL finished){

if (delegate && [delegate respondsToSelector:@selector(gridView:endMovePage:)]) {
[delegate gridView:self endMovePage:index];
Expand Down
4 changes: 2 additions & 2 deletions UzysGridView/ViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#import "UzysGridView.h"
@interface ViewController : UIViewController <UzysGridViewDelegate,UzysGridViewDataSource>
{
UzysGridView *gridView;
NSMutableArray *test_arr;
UzysGridView *_gridView;
NSMutableArray *_test_arr;
}
@end
47 changes: 34 additions & 13 deletions UzysGridView/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ - (void)didReceiveMemoryWarning
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}

-(void)dealloc
{
[_gridView release];

[super dealloc];
}
#pragma mark - View lifecycle

- (void)viewDidLoad
Expand All @@ -26,16 +31,16 @@ - (void)viewDidLoad
UIBarButtonItem *barBtn = [[[UIBarButtonItem alloc] initWithTitle:@"Edit" style:UIBarButtonItemStyleDone target:self action:@selector(ButtonTapp:)] autorelease];
self.navigationItem.rightBarButtonItem = barBtn;

gridView = [[UzysGridView alloc] initWithFrame:self.view.frame numOfRow:3 numOfColumns:2 cellMargin:2];
gridView.delegate = self;
gridView.dataSource = self;
[self.view addSubview:gridView];
_gridView = [[UzysGridView alloc] initWithFrame:self.view.frame numOfRow:3 numOfColumns:2 cellMargin:2];
_gridView.delegate = self;
_gridView.dataSource = self;
[self.view addSubview:_gridView];

test_arr = [[NSMutableArray alloc] init];
_test_arr = [[NSMutableArray alloc] init];

for(int i=0;i < 42;i++)
{
[test_arr addObject:[NSString stringWithFormat:@"%d",i]];
[_test_arr addObject:[NSString stringWithFormat:@"Content %d",i]];
}

// Do any additional setup after loading the view, typically from a nib.
Expand All @@ -53,7 +58,8 @@ - (IBAction) ButtonTapp :(id)sender
{
toggle = YES;
}
gridView.editable = toggle;
_gridView.editable = toggle;
[_gridView reloadData];
}
- (void)viewDidUnload
{
Expand Down Expand Up @@ -91,31 +97,46 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface



#pragma - UzysGridViewDataSource
#pragma mark- UzysGridViewDataSource

-(NSInteger) numberOfCellsInGridView:(UzysGridView *)gridview {
return [test_arr count];
return [_test_arr count];
}
-(UzysGridViewCell *)gridView:(UzysGridView *)gridview cellAtIndex:(NSUInteger)index
{
UzysGridViewCustomCell *cell = [[[UzysGridViewCustomCell alloc] initWithFrame:CGRectNull] autorelease];
cell.textLabel.text = [test_arr objectAtIndex:index];
cell.textLabel.text = [NSString stringWithFormat:@"Cell %d", index];
cell.textLabel.text = [_test_arr objectAtIndex:index];
cell.textLabel.text = [NSString stringWithFormat:@"%@", _test_arr[index]];
cell.backgroundView.backgroundColor = [UIColor scrollViewTexturedBackgroundColor];

if(index ==0)
cell.deletable = NO;
return cell;
}

- (void)gridView:(UzysGridView *)gridview moveAtIndex:(NSUInteger)fromindex toIndex:(NSUInteger)toIndex
{
NSMutableDictionary *Temp = [[_test_arr objectAtIndex:fromindex] retain];

[_test_arr removeObjectAtIndex:fromindex];
[_test_arr insertObject:Temp atIndex:toIndex];
[Temp release];
}

-(void) gridView:(UzysGridView *)gridview deleteAtIndex:(NSUInteger)index
{
[test_arr removeObjectAtIndex:index];
[_test_arr removeObjectAtIndex:index];
}

#pragma mark- UzysGridViewDelegate
-(void) gridView:(UzysGridView *)gridView changedPageIndex:(NSUInteger)index
{
NSLog(@"Page : %d",index);
}
-(void) gridView:(UzysGridView *)gridView didSelectCell:(UzysGridViewCell *)cell atIndex:(NSUInteger)index
{
NSLog(@"Cell index %d",index);
}
// ----------------------------------------------------------------------------------


Expand Down

0 comments on commit 9e139ef

Please sign in to comment.