//theme info // listTableView.backgroundColor = [UIColor blackColor];
// Register for application exiting information so we can save data [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:UIApplicationWillTerminateNotification object:nil];
// Uncomment the following line to display an Edit button in the navigation bar for this view controller. self.navigationItem.leftBarButtonItem = self.editButtonItem; }
// this adds a navication bar to the noteDetailViewController UINavigationController *addNavCon = [[UINavigationController alloc] initWithRootViewController:noteDetailViewControler]; noteDetailViewControler.noteArray = self.Notes;
// Customize the number of rows in the table view. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [self.Notes count]; }
// Customize the appearance of table view cells. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// this adds a navication bar to the noteDetailViewController UINavigationController *addNavCon = [[UINavigationController alloc] initWithRootViewController:noteDetailViewControler]; noteDetailViewControler.Notedict = [self.Notes objectAtIndex:indexPath.row]; noteDetailViewControler.noteArray = self.Notes;
/* // Override to support conditional editing of the table view. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { // Return NO if you do not want the specified item to be editable. return YES; } */
// Override to support editing the table view. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) { // Delete the row from the data source. // Delete the row from the data source. [self.Notes removeObjectAtIndex:indexPath.row]; [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
} else if (editingStyle == UITableViewCellEditingStyleInsert) { // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view. } }
/* // Override to support rearranging the table view. - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { } */
/* // Override to support conditional rearranging of the table view. - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { // Return NO if you do not want the item to be re-orderable. return YES; } */
- (void)createEditableCopyOfDatabaseIfNeeded { // First, test for existence - we don't want to wipe out a user's DB NSFileManager *fileManager = [NSFileManager defaultManager]; NSString *documentDirectory = [self applicationDocumentsDirectory]; NSString *writableDBPath = [documentDirectory stringByAppendingPathComponent:@"NotesList.plist"];
BOOL dbexits = [fileManager fileExistsAtPath:writableDBPath]; if (!dbexits) { // The writable database does not exist, so copy the default to the appropriate location. NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"NotesList.plist"];
NSError *error; BOOL success = [fileManager copyItemAtPath:defaultDBPath toPath:writableDBPath error:&error]; if (!success) { NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]); } } }
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after app launch
/* // The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) { // Custom initialization } return self; } */
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { [super viewDidLoad];
//if we edited lets save the note in case we're exiting for a text or incoming call if(didEdit){ [self savePlist];
} }
/* // Override to allow orientations other than the default portrait orientation. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait); } */
-(void) keyboardDidShow: (NSNotification *)notif { if (keyboardVisible) { //NSLog(@"Keyboard is already visible. Ignoring notofication."); return; }
//The keyboard wasn't visible before
// Get the size of the keyboard. NSDictionary* info = [notif userInfo]; NSValue* aValue = [info objectForKey:UIKeyboardBoundsUserInfoKey]; CGSize keyboardSize = [aValue CGRectValue].size;
if(self.Notedict != nil){ // We're working with an exisitng note, so let's remove // it from the array to get ready for a new one [noteArray removeObject:Notedict]; self.Notedict = nil; //This will release our reference too
}
// Add it to the master array and release our reference [noteArray addObject:newNote];
//important, without this it double creates your saved note on exit due to saving on viewWillDissapear didEdit = NO;
[newNote release];
// Sort the array since we just aded a new drink NSSortDescriptor *nameSorter = [[NSSortDescriptor alloc] initWithKey:@"CDate" ascending:NO selector:@selector(compare:)]; [noteArray sortUsingDescriptors:[NSArray arrayWithObject:nameSorter]]; [nameSorter release];
if(!didEdit) { [self dismissModalViewControllerAnimated:YES]; } else { // open a alert with an OK and cancel button UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Unsaved Changes!" message:@"Close without saving?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil]; [alert show]; [alert release];
}
}
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { // the user clicked one of the OK/Cancel buttons if (buttonIndex == 0) { //NSLog(@"cancel")
I've published the source code for the app GitHub. You can freely download. Please be published on this site as consideration for the feature you've added. Please write the link in the comments to the GitHub. This is an obligation. Thank you.