i am new in xcode. i hope someone will teach me more xcode.
i’m learning core data now, from what i learn, i can save my data from uitextfield using uibutton. this is my code.
- (IBAction)button1:(id)sender
{
TestSaveDataAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [appDelegate managedObjectContext];
Highscore *record = [NSEntityDescription insertNewObjectForEntityForName:@"Highscore" inManagedObjectContext:context];
record.highscore1 = textField.text;
NSLog(@"Saved for %@", textField.text);
NSError *error;
if (![context save:&error])
{
NSLog(@"Error");
}
now i have a UILabel call label and a button2 next to it. how do i load my data in my label when button2 is pushed? Please teach me.
i already wrote like this but i dont know how to put it in my label. any tutorial that i find only put it in tableview. i don’t want to put it in tableview, i just want my data show in my label.
- (IBAction)button2:(id)sender
{
TestSaveDataAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [appDelegate managedObjectContext];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Highscore" inManagedObjectContext:context];
[request setEntity:entity];
NSError *error;
if (![context save:&error])
{
NSLog(@"Error");
}
}
You have to add NSPredicate to your request and execute it.