Created
October 1, 2010 13:53
-
-
Save Kevinwlee/606245 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define YOUR_MODEL_SAVED @"YOUR_MODEL_SAVED_NOTIFICATION" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Prefix header for all source files of the 'bizeeti-iphone' target in the 'bizeeti-iphone' project | |
// | |
#ifdef __OBJC__ | |
#import <Foundation/Foundation.h> | |
#import <UIKit/UIKit.h> | |
#import "AppDelegate.h" | |
#import "Globals.h" | |
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(void)save:(YourModleObject *) model{ | |
FMDatabase *db = [self db]; | |
if(![db open]) { | |
NSLog(@"Error opening sqlite database!"); | |
exit(1); | |
} | |
[db beginTransaction]; | |
@try | |
{ | |
if(model.itemId != 0){ | |
[self updateYourModelObject:model withDB:db]; | |
} | |
else { | |
[self createYourModelObject:model withDB:db]; | |
} | |
[db commit]; | |
[[NSNotificationCenter defaultCenter] postNotificationName:YOUR_MODEL_SAVED object:bizFocusItem]; | |
} | |
@catch (id exception) { | |
NSLog(@"Rolling back, due to error!"); | |
[db rollback]; | |
@throw; | |
} | |
@finally { | |
[db close]; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[[NSNotificationCenter defaultCenter] postNotificationName:YOUR_MODEL_SAVED object:bizFocusItem]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(void)loadData{ | |
YourModelService *svc = [[YourModelService alloc] init]; | |
self.data = [svc ViewModels]; | |
[self.tableView reloadData]; | |
[svc release]; | |
} | |
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
[self loadData]; | |
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loadData) name:YOUR_MODEL_SAVED object:nil]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment