开发者

Making an UIButton add data to Core Data Model

Hey all, been scratching my head at this for a couple of days now, but still have no idea how to do it.

I have an UIButton, by clicking it I would like it to add data to my Core Data model. At the moment I'm using navigationItem.rightBarButtonItem开发者_开发百科 = addButton; from my Core Data UITableViewController to add data, but instead I like to connect a UIViewController to the core data model and have an UIButton add data to it.

For example, when this UIbutton is click, it would change to another view while also adding data to the core data model.

-(IBAction)changeviewandadddata {

SecondViewController *screen = [[SecondViewController alloc] initWithNibName:nil bundle:nil];
screen.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:screen animated:YES];
[screen release];

}

Any help or suggestions on how to do this would be appreciated.


Here is a sample to insert data into a Core Data store.

NSManagedObject *object = [NSEntityDescription insertNewObjectForEntityForName:@"EntityName" 
                                                        inManagedObjectContext:managedObjectContext];
[object setValue:@"test" forKey:@"something"];
NSError *error = nil;
if (![managedObjectContext save:&error]) {
    NSLog(@"Unresolved error %@, %@", error, [error userInfo]);

    //handle the error
    [managedObjectContext rollback];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜