Skip to content

Instantly share code, notes, and snippets.

@amannayak0007
Created January 19, 2015 16:40
Show Gist options
  • Save amannayak0007/7db92466d4c9025355dc to your computer and use it in GitHub Desktop.
Save amannayak0007/7db92466d4c9025355dc to your computer and use it in GitHub Desktop.
#import "NNPDetailViewController.h"
@interface NNPDetailViewController ()
- (void)configureView;
- (void)setCompletedImage:(NSInteger)completed;
- (void)updateToDoObject:(ToDo *)object;
@property (weak, nonatomic) IBOutlet UIDatePicker *reminderDate;
@end
@implementation NNPDetailViewController
@synthesize delegate = _delegate;
@synthesize parentCellIndexPath = _parentCellIndexPath;
@synthesize detailItem = _detailItem;
@synthesize task = _task;
@synthesize nameTxtField = _nameTxtField;
@synthesize descriptionTxtField = _descriptionTxtField;
@synthesize prioritySegCtrl = _prioritySegCtrl;
@synthesize completedBtn = _completedBtn;
#pragma mark - Managing the detail item
-(void) setCompletedImage:(NSInteger)completed {
//todo2 -- bez rozszerzenia
if (!_doneImg || !_notDoneImg) {
_doneImg = [UIImage imageNamed:@"check"];
_notDoneImg = [UIImage imageNamed:@"checkblank"];
}
UIImage *image = (completed == 1 ? _doneImg : _notDoneImg);
[self.completedBtn setImage:image forState:UIControlStateNormal];
}
-(void)updateToDoObject:(ToDo *)object {
object.toDo = self.nameTxtField.text;
object.toDoDescription = self.descriptionTxtField.text;
object.toDoPriority = self.prioritySegCtrl.selectedSegmentIndex;
object.toDoCompletedInd = _completedIndState;
}
-(IBAction)saveBtnTapped:(id)sender {
if (self.nameTxtField.text.length > 0) {
self.task = [[ToDo alloc] init];
self.task.toDo = self.nameTxtField.text;
self.task.toDoDateCreated = self.reminderDate.date;
NSLog(@"reminderDate: %@", self.task.toDoDateCreated);
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
localNotif.fireDate = self.task.toDoDateCreated;
localNotif.timeZone = [NSTimeZone defaultTimeZone];
localNotif.alertBody = self.task.toDo;
localNotif.applicationIconBadgeNumber = 1;
localNotif.soundName = UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
}
if (self.parentCellIndexPath) {
//updating...
[self updateToDoObject:self.task];
[self.delegate refreshTableAfter:UPDATE :self.task :self.parentCellIndexPath];
[self.navigationController popViewControllerAnimated:YES];
}
else {
//inserting...
ToDo *tempTask = [[ToDo alloc] init];
[self updateToDoObject:tempTask];
tempTask.toDoID = -1;
if ([tempTask.toDo length] > 0) {
[self.delegate refreshTableAfter:INSERT :tempTask :nil];
}
[self dismissViewControllerAnimated:YES completion:nil];
}
}
-(IBAction)deleteBtnTapped:(id)sender {
if (self.parentCellIndexPath) {
[self.delegate refreshTableAfter:DELETE :self.task :self.parentCellIndexPath];
[self.navigationController popViewControllerAnimated:YES];
} else {
[self dismissViewControllerAnimated:YES completion:nil];
}
}
- (void)setDetailItem:(id)newDetailItem
{
if (_detailItem != newDetailItem) {
_detailItem = newDetailItem;
// Update the view.
[self configureView];
}
}
- (void)configureView
{
// Update the user interface for the detail item.
//todo2
if (self.detailItem) {
self.task = (ToDo *)self.detailItem;
self.nameTxtField.text = self.task.toDo;
self.descriptionTxtField.text = self.task.toDoDescription;
self.prioritySegCtrl.selectedSegmentIndex = self.task.toDoPriority;
_completedIndState = self.task.toDoCompletedInd;
[self setCompletedImage:self.task.toDoCompletedInd];
} else {
_completedIndState = 0;
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self configureView];
}
- (void)viewDidUnload
{
[self setNameTxtField:nil];
[self setDescriptionTxtField:nil];
[self setPrioritySegCtrl:nil];
[self setCompletedBtn:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (IBAction)completedBtnTapped:(id)sender {
if (_completedIndState == 1) {
_completedIndState = 0;
} else {
_completedIndState = 1;
}
[self setCompletedImage:_completedIndState];
}
- (IBAction)hideKeyboard:(id)sender {
[(UITextField *)sender resignFirstResponder];
}
- (IBAction)backgroundTap:(id)sender {
[self.view endEditing:YES];
}
-(BOOL) textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment