gpt4 book ai didi

iphone - 删除核心数据中的对象

转载 作者:IT王子 更新时间:2023-10-29 07:53:22 27 4
gpt4 key购买 nike

我如何删除之前使用此代码添加的对象。它是一个收藏夹部分,在开始时,我添加了一个灰色星号,它添加了一个来自获取的对象。然后它变成黄色,向后的方法应该是 star yellow = deletes。

但我不知道该怎么做。

-(IBAction)inFavoris:(id)sender {



AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];

NSManagedObjectContext *context = [appDelegate managedObjectContext];
NSManagedObject *favorisObj = [NSEntityDescription
insertNewObjectForEntityForName:@"Favoris"
inManagedObjectContext:context];


[favorisObj setValue:idTaxi forKey:@"idTaxi"];
[favorisObj setValue:nomTaxi forKey:@"nomTaxi"];
[favorisObj setValue:taxiCB forKey:@"cb"];
[favorisObj setValue:taxiAvion forKey:@"avion"];
[favorisObj setValue:taxiColis forKey:@"colis"];
[favorisObj setValue:taxiHandicape forKey:@"handicape"];
[favorisObj setValue:taxiHoraires forKey:@"horaire"];
[favorisObj setValue:lugagge forKey:@"lugagge"];
[favorisObj setValue:luxury forKey:@"luxury"];
[favorisObj setValue:languesParlees forKey:@"langues"];
[favorisObj setValue:taxiNote forKey:@"note"];
[favorisObj setValue:taxiPassengers forKey:@"passenger"];
[favorisObj setValue:taxiVote forKey:@"etoiles"];
[favorisObj setValue:taxiTel forKey:@"tel"];


[self.view addSubview:favorisB];

}

更新

我做了这个方法..它完成了工作:)

-(IBAction)outFavoris:(id)sender {


AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
NSString *testEntityId = idTaxi;
NSManagedObjectContext *moc2 = [appDelegate managedObjectContext];

NSFetchRequest *fetch = [[NSFetchRequest alloc] init];
fetch.entity = [NSEntityDescription entityForName:@"Favoris" inManagedObjectContext:moc2];
fetch.predicate = [NSPredicate predicateWithFormat:@"idTaxi == %@", testEntityId];
NSArray *array = [moc2 executeFetchRequest:fetch error:nil];




for (NSManagedObject *managedObject in array) {
[moc2 deleteObject:managedObject];
}


[self.view addSubview:favorisO];

}

最佳答案

很简单:)

[context deleteObject:favorisObj];

坏对象都消失了。

更新

如果您需要一个按钮来删除对象,您只需使用类似这样的东西来反转它。

-(IBAction)removeFavoris:(id)sender {

AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];

NSManagedObjectContext *context = [appDelegate managedObjectContext];

[context deleteObject:favorisObj];
}

关于iphone - 删除核心数据中的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11039575/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com