0

iPad app fans:

I've got a modalviewcontroller designed to popup on a button tap so users can add notes or change data inputs. A table in the main window needs to be refreshed as changes to the database are made. The database incorporates a kind of advanced bookmark. I can create and delete database entries based on where users browse - no problem: I get the console report "saveContext KQVC line 203" and entries are quickly added into the table.

The modalviewcontroller even pops (on tapping the blue (>) detail icon also in each cell) with populated data of existing records. However the save button on the modalviewcontroller just doesn't save. (the delete function works great). Here's my code for the modalviewcontroller save button:

#import "PatternViewController.h"
#import "KnittingQueenViewController.h"

 @implementation PatternViewController
 @dynamic patternName, patternNotes, patternUrl, dateAdded;
 @synthesize patternA, patternView, knittingQueenViewController;

-(IBAction)save {
    [patternA setValue:patternName.text forKey:@"patternName"];
    [patternA setValue:patternUrl.text forKey:@"patternUrl"];
    [patternA setValue:patternNotes.text forKey:@"patternNotes"];
    dateAdded = [NSDate date];
    [patternA setValue:dateAdded forKey:@"dateAdded"];
    [patternA setValue:patternLabel.text forKey:@"patternLabel"];
    [patternA setValue:pngPath forKey:@"patternPhoto"];   

    [knittingQueenViewController saveContext];
    [self dismissModalViewControllerAnimated:YES];
}

and the saveContext method in the knittingqueenviewcontroller:

- (void)saveContext {
    NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext]; 
    NSError *error = nil;
    if (![context save:&error]) {
         // error code goes in here
    }
    NSLog(@"saveContext KQVC line 203");
    [self refreshPatternsTable];
}

I get no errors, but no saved data either. My question: why isn't the method saveContext being called from the modalviewcontroller? Any suggestions you can offer would be most appreciated.

1 Answer 1

3

Is your save method being called? Is knittingQueenViewController non-nil when it's called? Do the values of patternA look correct?

Sign up to request clarification or add additional context in comments.

9 Comments

One of the first two questions here is almost certainly the issue.
@noa Answer to Q1: the method was being called but because the knittingQueenViewController was nil stackoverflow.com/questions/3678180/… tested per this answer. Answer to Q2: it was nil. So I've alloc init and now it crashes.
Allocating another one here won't help you – it doesn't have a references to your FetchedResultsController or ManagedObjectContext, for example. Where do you first allocate and initialize PatternViewController? From code? You probably need to add some code there that sets knittingQueenViewController to the already-created instance.
@noa Yes, it's from code. Here's the allocate and initialize of PatternViewController in KnittingQueenViewController. -(IBAction)newPattern { PatternViewController *controller = [[PatternViewController alloc] initWithNibName:@"PatternViewController" bundle:nil]; controller.modalTransitionStyle = UIModalTransitionStyleCoverVertical; controller.modalPresentationStyle = UIModalPresentationFormSheet; [self presentModalViewController:controller animated:YES]; [controller release]; } What would you suggest?
Cool. Just add controller.knittingQueenViewController = self; after the call to initWithNibName.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.