Skip to content

Instantly share code, notes, and snippets.

@quique123
Created January 30, 2011 02:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quique123/802433 to your computer and use it in GitHub Desktop.
Save quique123/802433 to your computer and use it in GitHub Desktop.
- (void)save {
[shipment setValue:nameTextField.text forKey:@"shipperName"];
[shipment setValue:[NSDate date] forKey:@"rfqDate"];
NSError *error = nil;
if (![shipment.managedObjectContext save:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
NSLog(@"calling rAVC delegate-save");
[self.delegate addShipmentModalVC:self didAddShipment:shipment];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSInteger section = indexPath.section;
EditingViewController *nextViewController = [[EditingViewController alloc] initWithNibName:@"EditingViewController" bundle:nil];
((EditingViewController *)nextViewController).shipment = shipment;
NSLog(@"shipment = %@", shipment);
nextViewController.editedObject = shipment;
switch (section) {
case MONIES_SECTION:
NSLog(@"Monies Selected");
nextViewController.editingDate = NO;
switch (indexPath.row) {
case 1:
nextViewController.editedFieldKey = @"orderAmount";
nextViewController.editedFieldName = NSLocalizedString(@"orderAmount", @"display name for title");
break;
case 2:
nextViewController.editedFieldKey = @"initialWireAmount";
nextViewController.editedFieldName = NSLocalizedString(@"initialWireAmount", @"display name for title");
break;
...
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
// Configure the user interface according to state.
if (editingDate) {
// make picker visible...
textField.hidden = YES;
datePicker.alpha = 1;
NSDate *date = [editedObject valueForKey:editedFieldKey];
if (date==nil) date = [NSDate date];
datePicker.date = date;
}
else {
// otherwise hide picker and make textfields visible, or place behind picker :)
textField.hidden = NO;
datePicker.alpha = 0;
NSLog(@"NO DATE EDITING");
NSLog(@"eFK: %@, eFN: %@",editedFieldKey, editedFieldName);
textField.text = [editedObject valueForKey:editedFieldKey];
[textField becomeFirstResponder];
}
}
#pragma mark -
#pragma mark Save and cancel operations
- (IBAction)save {
// Set the action name for the undo operation.
NSUndoManager *undoManager = [[editedObject managedObjectContext] undoManager];
[undoManager setActionName:[NSString stringWithFormat:@"%@", editedFieldName]];
if (editingDate) {
[editedObject setValue:datePicker.date forKey:editedFieldKey];
}
else {
[editedObject setValue:textField.text forKey:editedFieldKey];
}
[self.navigationController popViewControllerAnimated:YES];
}
- (void)addShipment:(id)sender {
AddShipmentModalVC *addController = [[AddShipmentModalVC alloc] initWithNibName:@"AddShipmentModalVC" bundle:nil];
addController.delegate = self;
// Create and configure a new instance of the Shipment entity
Shipment *newShipment = (Shipment *)[NSEntityDescription insertNewObjectForEntityForName:@"Shipment" inManagedObjectContext:managedObjectContext];
addController.shipment = newShipment;
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:addController];
[self presentModalViewController:navigationController animated:YES];
// why are they released this early?
[navigationController release];
[addController release];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment