NSTextView does not display updated values from core-data
NSTextView does not display updated values from core-data
- Subject: NSTextView does not display updated values from core-data
- From: Joseph Jude <email@hidden>
- Date: Tue, 10 Jul 2012 14:32:32 +0530
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
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden