IPhone : Fetching data from core data

on Monday, March 30, 2015

I am using following code to fetch data from core database. But when I am pushing another view controller on current view and change some text on any text field and click cancel button without saving/updating text into DB.After clicking on cancel button I pop this view controller and then this method call again from viewDidApear method and then that edited text is come from following method. But I didn't save/update that text into database.



-(Notes *)fetchSpecificNoteWithNoteID:(NSString* )noteID
{

NSEntityDescription *roomObj = [NSEntityDescription entityForName:@"Notes"
inManagedObjectContext:[[self appDelegate] managedObjectContext]];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSError *error = nil;
NSPredicate *predicate =[NSPredicate predicateWithFormat:@"notesID=%@",noteID];
[request setPredicate:predicate];

[request setEntity:roomObj];
NSArray *array = [[[self appDelegate] managedObjectContext] executeFetchRequest:request error:&error];
if ([array count] && array) {
return [array objectAtIndex:0];
}
return nil;
}

0 comments:

Post a Comment