Database Reference
In-Depth Information
-(void)btnBackPressed:(id)sender {
NSError *error = nil;
if(![[AppDelegate managedObjectContext] save:&error]){
NSLog(@"There was an error saving date - %@",error.localizedDescription);
[[[UIAlertView alloc] initWithTitle:@"Error" message:[NSString stringWithFormat:@"There
was an error saving data - %@",error.localizedDescription] delegate:nil cancelButtonTitle:@"OK"
otherButtonTitles:nil] show];
} else {
[_delegate detailViewControllerDidClose:self];
}
}
-(void)btnDatePickerDonePressed:(id)sender {
static NSDateFormatter *dateFormatter = nil;
if (dateFormatter == nil) {
dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
}
UIDatePicker *datePicker = (UIDatePicker *)_txtBirthday.inputView;
_txtBirthday.text = [dateFormatter stringFromDate:datePicker.date];
[_txtBirthday resignFirstResponder];
}
The first method btnEditPressed: enables all the fields for editing by calling our enableAllFields
method. Then we create a UIBarButtonItem titled “Done” and give it an action of btnDonePressed: .
We replace the right Bar Button item with our Done button and remove the left Bar Button item.
Removing the left Bar Button item makes sure that the user is not in an edit mode when they return
to the collection view.
The second method is btnDonePressed: . We disable all the fields by calling our disableAllFields
method. Then we set up the Bar Buttons back to their original state by creating an editButton and a
Back button, adding those to our navigation item.
The third method is btnBackPressed: and we simply perform a save on our managed object context.
If it fails, we show an alert message and use NSLog to log the message to console for debugging. If
all is well, then we call our delegate method detailViewControllerDidClose: and pass our self as
the parameter.
Wrapping Up Our View Controller Code
The last thing we need to do is set up our viewDidLoad :
- (void)viewDidLoad
{
[super viewDidLoad];
_dateFormatter = [[NSDateFormatter alloc] init];
[_dateFormatter setDateStyle:NSDateFormatterMediumStyle];
 
Search WWH ::




Custom Search