Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何编辑实体中某些属性的值?_Ios_Core Data_Editing - Fatal编程技术网

Ios 如何编辑实体中某些属性的值?

Ios 如何编辑实体中某些属性的值?,ios,core-data,editing,Ios,Core Data,Editing,如何通过点击按钮编辑CoreData实体SQLite中某些字段的值 例如,在我的UITableViewCell中,我有一个按钮。我想用这个按钮来改变一些布尔字段的值。通过第一次点击,我想写“是”,第二次写“否” 1.Join是一个手动创建的Join表Components>Join首先获取要修改的对象 NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEnti

如何通过点击按钮编辑CoreData实体SQLite中某些字段的值

例如,在我的UITableViewCell中,我有一个按钮。我想用这个按钮来改变一些布尔字段的值。通过第一次点击,我想写“是”,第二次写“否”


1.Join是一个手动创建的Join表Components>Join首先获取要修改的对象

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"entityName" inManagedObjectContext:managedObjectContext];
[fetchRequest setEntity:entity];
[fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"(id == %@)", eID]];
NSError *error;

NSArray *details = [managedObjectContext executeFetchRequest:fetchRequest error:&error];
entityName *objEntity= nil;
//error handling goes here
if([details count] > 0)
    objEntity = (entityName *)[details objectAtIndex:0];
现在,在插入实体时更新该实体

    if(objEntity){
    club.fieldName = @"YES";
    NSError *error = nil;
    if(![self.managedObjectContext save:&error])
        NSLog(@"Error updating");
}

你的意思是,当用户点击时,你只想更改按钮标题???你尝试了什么,发布你的帖子code@iPatel:否,我想更改数据库中的值它正常工作,但它编辑了另一条记录。。。在执行此操作之前,我需要知道记录ID这只是一个示例,您需要创建适当的谓词来获取所需的对象,然后更新ITCellForRowatineXpath将调用所有对象,因此我认为只有最后加载的对象会被修改,您应该更新didselect方法
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"entityName" inManagedObjectContext:managedObjectContext];
[fetchRequest setEntity:entity];
[fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"(id == %@)", eID]];
NSError *error;

NSArray *details = [managedObjectContext executeFetchRequest:fetchRequest error:&error];
entityName *objEntity= nil;
//error handling goes here
if([details count] > 0)
    objEntity = (entityName *)[details objectAtIndex:0];
    if(objEntity){
    club.fieldName = @"YES";
    NSError *error = nil;
    if(![self.managedObjectContext save:&error])
        NSLog(@"Error updating");
}