Permalink
Browse files

ReloadData with Animation, added some delegate methods for placeholding

  • Loading branch information...
1 parent e32e369 commit 2dd232bc23dc42d3ea6e3de1e1f53e0298fda1fc @pppoe committed Jun 16, 2011
@@ -8,9 +8,10 @@
#import <UIKit/UIKit.h>
+@class OmniGridView;
@interface OmniGridTestViewController : UIViewController {
-
+ OmniGridView *_gridView;
}
@end
@@ -20,12 +20,34 @@ @implementation OmniGridTestViewController
- (void)viewDidLoad {
[super viewDidLoad];
- OmniGridView *gridView = [[OmniGridView alloc] initWithFrame:CGRectMake(0, 0, 400, 400)];
+ UIBarButtonItem *refreshItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
+ target:self
+ action:@selector(refresh)];
+ self.navigationItem.leftBarButtonItem = refreshItem;
+ [refreshItem release];
+
+ UIBarButtonItem *editItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit
+ target:self
+ action:@selector(edit)];
+ self.navigationItem.rightBarButtonItem = editItem;
+ [editItem release];
+
+ OmniGridView *gridView = [[OmniGridView alloc] initWithFrame:CGRectMake(0, 0, 480, 300)];
gridView.gridDelegate = self;
gridView.backgroundColor = [UIColor lightGrayColor];
+
+ _gridView = gridView;
+
[self.view addSubview:gridView];
[gridView release];
}
+
+- (void)refresh {
+ [_gridView reloadData];
+}
+
+- (void)edit {
+}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
@@ -35,8 +57,6 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
-
- // Release any cached data, images, etc. that aren't in use.
}
- (void)viewDidUnload {
@@ -62,17 +82,17 @@ - (OmniGridCell *)gridCellAt:(OmniGridLoc *)gridLoc inGridView:(OmniGridView *)g
gridCell.textLabel.textAlignment = UITextAlignmentCenter;
}
- gridCell.textLabel.text = [NSString stringWithFormat:@"(%d,%d)", gridLoc.row, gridLoc.col];
+ gridCell.textLabel.text = [NSString stringWithFormat:@"(%d,%d), %d", gridLoc.row, gridLoc.col, random()%10];
return gridCell;
}
- (float)gridCellHeightInGridView:(OmniGridView *)gridView {
- return 200.0f;
+ return 100.0f;
}
- (float)gridCellWidthInGridView:(OmniGridView *)gridView {
- return 200.0f;
+ return 100.0f;
}
- (int)numberOfGridCellsInRow:(int)row inGridView:(OmniGridView *)gridView {
View
@@ -15,11 +15,17 @@
id<OmniGridViewDelegate> _gridDelegate;
NSMutableDictionary *_gridCellsDict;
NSMutableArray *_reusableGridCells;
+
+ BOOL _editing;
}
@property (nonatomic, assign) id<OmniGridViewDelegate> gridDelegate;
+@property(nonatomic,getter=isEditing) BOOL editing;
+- (void)setEditing:(BOOL)editing;
+
- (void)reloadData;
+- (void)reloadDataAnimated:(BOOL)animated;
- (OmniGridCell *)dequeueReusableGridCell;
View
@@ -11,15 +11,17 @@
#import "OmniGridLoc.h"
#import "OmniGridViewDelegate.h"
+#import <QuartzCore/QuartzCore.h>
+
@interface OmniGridView (Private)
- (NSString *)keyFromGridLoc:(OmniGridLoc *)gridLoc;
@end
-
@implementation OmniGridView
@synthesize gridDelegate = _gridDelegate;
+@synthesize editing = _editing;
- (id)initWithFrame:(CGRect)frame {
@@ -95,10 +97,33 @@ - (void)layoutSubviews {
}
}
}
+
+ [self performSelector:@selector(scrollViewDidScroll:)
+ withObject:self
+ afterDelay:0.0f];
}
#pragma mark Methods
+- (void)setEditing:(BOOL)editing {
+ _editing = editing;
+}
+
- (void)reloadData {
+ [self reloadDataAnimated:NO];
+}
+
+- (void)reloadDataAnimated:(BOOL)animated {
+ for (OmniGridCell *gridCell in [_gridCellsDict allValues])
+ {
+ [gridCell removeFromSuperview];
+ }
+ [_gridCellsDict removeAllObjects];
+ [_reusableGridCells removeAllObjects];
+
+ CATransition *animation = [CATransition animation];
+ animation.type = kCATransitionFade;
+ [self.layer addAnimation:animation forKey:@"reloadData"];
+ [self setNeedsLayout];
}
- (OmniGridCell *)dequeueReusableGridCell {
@@ -8,11 +8,9 @@
#import <UIKit/UIKit.h>
-@class OmniGridTestViewController;
-
@interface OmniGridViewAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
- OmniGridTestViewController *viewController;
+ UINavigationController *navController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@@ -18,8 +18,11 @@ @implementation OmniGridViewAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
- viewController = [[OmniGridTestViewController alloc] init];
- [self.window addSubview:viewController.view];
+ OmniGridTestViewController *viewController = [[OmniGridTestViewController alloc] init];
+ navController = [[UINavigationController alloc] initWithRootViewController:viewController];
+ [viewController release];
+
+ [self.window addSubview:navController.view];
[self.window makeKeyAndVisible];
return YES;
@@ -59,7 +62,7 @@ Free up as much memory as possible by purging cached data objects that can be re
- (void)dealloc {
- [viewController release];
+ [navController release];
[window release];
[super dealloc];
}
@@ -19,4 +19,9 @@
- (int)numberOfGridCellsInRow:(int)row inGridView:(OmniGridView *)gridView;
- (int)numberOfRowsInGridView:(OmniGridView *)gridView;
+@optional
+- (void)gridView:(OmniGridView *)gridView willDisplayCell:(OmniGridCell *)cell forGridLoc:(OmniGridLoc *)gridLoc;
+- (void)gridView:(OmniGridView *)gridView didSelectCellAtLoc:(OmniGridLoc *)gridLoc;
+- (BOOL)gridView:(OmniGridView *)gridView shouldEditCellAtLoc:(OmniGridLoc *)gridLoc;
+
@end
Oops, something went wrong.

0 comments on commit 2dd232b

Please sign in to comment.