Edit data from table

Send Snippet To: Save this snippet to Code Collector Pro -- view all haxis's snippets
language: Objective-C
license: Other

Code for Snippet:

//View 1
#import "RoleDetailTVC.h" // so this class can be an RoleDetailTVCDelegate
@property (strong, nonatomic) Role *selectedRole;
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
if ([segue.identifier isEqualToString:@"Role Detail Segue"])
        //Setting RolesTVC as a delegate of RoleDetailTVC
        RoleDetailTVC *roleDetailTVC = segue.destinationViewController;
        roleDetailTVC.delegate = self;
        roleDetailTVC.managedObjectContext = self.managedObjectContext;
        // Store selected Role in selectedRole property
        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
        self.selectedRole = [self.fetchedResultsController objectAtIndexPath:indexPath];
        //Passing selected role to View 2
        roleDetailTVC.role = self.selectedRole;
- (void)theSaveButtonOnTheRoleDetailTVCWasTapped:(RoleDetailTVC *)controller
    // do something here like refreshing the table or whatever
    // close the delegated view
    [controller.navigationController popViewControllerAnimated:YES];    
//View 2
@property (strong, nonatomic) Role *role;
- (void)viewDidLoad 
    //Setting the value of fields in this static table to that of the passed Role
    self.roleNameTextField.text = self.role.name;
    [super viewDidLoad];
- (IBAction)save:(id)sender
    [self.role setName:roleNameTextField.text];
    [self.managedObjectContext save:nil];  // write to database
    [self.delegate theSaveButtonOnTheRoleDetailTVCWasTapped:self];
comments powered by Disqus


Tags: Coredata

Link to this snippet:

Download to Code Collector

To use the direct link to your snippet on CodeCollector.net either copy the html from the above section or drag the Download to Code Collector to where you would like to use it.

More Info:

Times Viewed: 690
Date Added: 2012-11-22 16:44:27
Last Modified: 0000-00-00 00:00:00

Web Analytics