NSTextView does not display updated values from core-data

  • Hello all,
    I got two entities - blog & entries in the core-data model. There is a
    table view to display titles and depending on the title selected, on
    another pane the values for the selected entry (title, tags, content etc)
    are displayed.

    Here is my problem: When I modify the body content (which is a NSTextView),
    save and then go up and down on NSTableView rows, the same body content is
    displayed for the updated row and the previous row but other values like
    title, tags are respective to the selected row. When I quit and restart it
    works fine until I do edit & save.

    When I replace NSTextView with NSTextField, then there is no problem. It
    behaves as expected.

    Am not sure if the issue is with storing data or with NSTextView (since if
    I replace it with text field, it is normal behaviour). Any pointers to
    debug & fix? Relevant code snippets:

    //this is called from appcontroller to display values
    -(void)displayValuesForSelectedEntry{
    BlogManager *aBlogManager = [[BlogManager alloc]init];

    NSManagedObject *selectedEntry = [aBlogManager
    readAnEntryLocally:[[entriesArray objectAtIndex:[entriesList selectedRow]]
    valueForKey:@"title"]

    ForBlog:[blogsList titleOfSelectedItem]];
    //other code trunctated
    NSAttributedString *aContent = [[NSAttributedString alloc]
    initWithString:[selectedEntry valueForKey:@"content"]];
    [[entryContent textStorage] setAttributedString:aContent];
    [aContent release];

    [aBlogManager release];
    }

    //called from appcontroller to save
    -(IBAction)saveSelectedEntry:(id)sender{

    [currentEntry setValue:[[entryContent textStorage] string] forKey:@
    "entryContent"];

    BlogManager *aBlogManager = [[BlogManager alloc]init];
    [aBlogManager saveAnEntryLocally:currentEntry];

    [aBlogManager release];
    }

    //blog manager
    NSManagedObjectContext *moc = [[NSApp delegate] managedObjectContext];
    //set the blog first
    NSEntityDescription *blogEntity = [NSEntityDescription
      entityForName:@"Blogs" inManagedObjectContext:moc];
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"blogName==%@",
    [anEntryWithBlogDetails valueForKey:@"blogName"]];
    NSFetchRequest *fetch = [[NSFetchRequest alloc] init];
    [fetch setEntity: blogEntity];
    [fetch setPredicate: predicate];
    NSError *error = nil;
    NSArray *results = [moc executeFetchRequest:fetch error:&error];
    NSManagedObject *aBlog = [results lastObject];
    NSEntityDescription *entryEntity = [NSEntityDescription
      entityForName:@"Entries" inManagedObjectContext:moc];
    predicate = [NSPredicate predicateWithFormat:@"self==%@",
    [anEntryWithBlogDetails valueForKey:@"objectId"] ];
    [fetch setEntity: entryEntity];
    [fetch setPredicate: predicate];
    results = [moc executeFetchRequest:fetch error:&error];
    [fetch release];

    NSManagedObject *anEntry;
    if([results count] == 0){
    anEntry = [NSEntityDescription insertNewObjectForEntityForName:@"Entries"
    inManagedObjectContext:moc];
    }
    else{
    anEntry = [results lastObject];
    }
    [anEntry setValue:[anEntryWithBlogDetails valueForKey:@"entryContent"]
    forKey:@"body"];
    [anEntry setValue:aBlog forKey:@"entryForBlog"];
    NSError *saveError = nil;
    if(![moc save:&saveError]){
    NSLog(@"there was error while saving the blog: %@", saveError);
    } //save block
    }

    Thank you,
    Joseph
previous month july 2012 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today