私はiOSで新しく、コアデータに配列のremaningデータを保存するという問題に直面しています。 私はテーブルビューからワンボタンを選択していると私のコードは、全体保存するには、このObjective Cのコアデータにアレイのremaningデータを保存する方法
NSString *[email protected]"";
NSString *[email protected]"";
NSManagedObjectContext *context = [self managedObjectContext];
NSError *error;
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:[NSEntityDescription entityForName:@"AuditPost" inManagedObjectContext:context]];
// NSError *error = nil;
NSArray *results = [context executeFetchRequest:request error:&error];
NSLog(@"Result =%@",results);
int imageSize = imgData.length;
NSLog(@"size of image in KB: %d ", imageSize/1024);
int OCS=imageSize/1024;
NSLog(@"OCS Image Size =%d",OCS);
if(OCS<2)
{
[email protected]"";
}
ComplareArray=[devices valueForKey:@"checkpointid"];
BOOL contains = [ComplareArray containsObject:String2];
if(contains == NO)
{
if (self.device) {
// Update existing device
[device setValue:Audit forKey:@"auditnameId"];
[device setValue:String forKey:@"checklistid"];
[device setValue:String2 forKey:@"checkpointid"];
[device setValue:FailString forKey:@"failreason"];
[device setValue:WarningString forKey:@"warningreason"];
[device setValue:AuditStartDate forKey:@"starttimedate"];
[device setValue:userid forKey:@"userid"];
[device setValue:AuditImageString forKey:@"auditimage"];
NSError *error = nil;
// Save the object to persistent store
if (![context save:&error]) {
NSLog(@"Can't Save! %@ %@", error, [error localizedDescription]);
}
} else {
// Create a new device
NSManagedObject *newDevice = [NSEntityDescription insertNewObjectForEntityForName:@"AuditPost" inManagedObjectContext:context];
[newDevice setValue:Audit forKey:@"auditnameId"];
[newDevice setValue:String forKey:@"checklistid"];
[newDevice setValue:String2 forKey:@"checkpointid"];
[newDevice setValue:FailString forKey:@"failreason"];
[newDevice setValue:WarningString forKey:@"warningreason"];
[newDevice setValue:AuditStartDate forKey:@"starttimedate"];
[newDevice setValue:userid forKey:@"userid"];
[newDevice setValue:AuditImageString forKey:@"auditimage"];
NSError *error = nil;
// Save the object to persistent store
if (![context save:&error]) {
NSLog(@"Can't Save! %@ %@", error, [error localizedDescription]);
}
}
}
else
{
NSError *error = nil;
// Save the object to persistent store
if (![context save:&error]) {
NSLog(@"Can't Save! %@ %@", error, [error localizedDescription]);
}
NSManagedObjectContext *context = [self managedObjectContext];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:[NSEntityDescription entityForName:@"AuditPost" inManagedObjectContext:context]];
NSArray *results = [context executeFetchRequest:request error:&error];
NSManagedObject* favoritsGrabbed = [results objectAtIndex:CurrentIndexPath];
[favoritsGrabbed setValue:String forKey:@"checklistid"];
// Save the object to persistent store
if (![context save:&error]) {
NSLog(@"Can't Save! %@ %@", error, [error localizedDescription]);
}
}
//example reload table
dispatch_async(dispatch_get_main_queue(), ^{
[Audittable reloadData];
});
のようなものであることについて、それはコアデータに
を値を保存する画像
に示すように、コアデータの配列私はこのようなコードを使用しています
if (self.device)
{
// Update existing device
[device setValue:Audit forKey:@"auditnameId"];
[device setValue:[NSString stringWithFormat:@"%@",Passarray[i]] forKey:@"checklistid"];
[device setValue:[NSString stringWithFormat:@"%@",CheckpointNameIDArray[i]] forKey:@"checkpointid"];
[device setValue:FailString forKey:@"failreason"];
[device setValue:WarningString forKey:@"warningreason"];
[device setValue:AuditStartDate forKey:@"starttimedate"];
[device setValue:userid forKey:@"userid"];
[device setValue:[NSString stringWithFormat:@"%@",AuditImageString] forKey:@"auditimage"];
NSError *error = nil;
// Save the object to persistent store
if (![context save:&error]) {
NSLog(@"Can't Save! %@ %@", error, [error localizedDescription]);
}
}
else
{
// Create a new device
NSManagedObject *newDevice = [NSEntityDescription insertNewObjectForEntityForName:@"AuditPost" inManagedObjectContext:context];
[newDevice setValue:Audit forKey:@"auditnameId"];
[newDevice setValue:[NSString stringWithFormat:@"%@",Passarray[i]] forKey:@"checklistid"];
[newDevice setValue:[NSString stringWithFormat:@"%@",CheckpointNameIDArray[i]] forKey:@"checkpointid"];
[newDevice setValue:FailString forKey:@"failreason"];
[newDevice setValue:WarningString forKey:@"warningreason"];
[newDevice setValue:AuditStartDate forKey:@"starttimedate"];
[newDevice setValue:userid forKey:@"userid"];
[newDevice setValue:[NSString stringWithFormat:@"%@",AuditImageString] forKey:@"auditimage"];
NSError *error = nil;
// Save the object to persistent store
if (![context save:&error]) {
NSLog(@"Can't Save! %@ %@", error, [error localizedDescription]);
}
}
}
for (int i=0; i<PassarrIndexPaths.count; i++)
{
AuditNextTableViewCell *cell = [Audittable cellForRowAtIndexPath:[PassarrIndexPaths objectAtIndex:i]];
DataModel *model = [arrData objectAtIndex:i];
model.strSelected = @"P";
[cell.passbtn setBackgroundColor:[UIColor greenColor]];
[cell.failbtn setBackgroundColor:[UIColor lightGrayColor]];
[cell.wipbtn setBackgroundColor:[UIColor lightGrayColor]];
[cell.nabtn setBackgroundColor:[UIColor lightGrayColor]];
}
// Passbtn.backgroundColor=[UIColor greenColor];
// NAbtn.backgroundColor=[UIColor lightGrayColor];
[Audittable reloadData];
画像
と同様
私はマーク・保留中として上でクリックした場合には、それは私がこの
NSManagedObjectContext *managedObjectContext = [self managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"AuditPost"];
self.devices = [[managedObjectContext executeFetchRequest:fetchRequest error:nil] mutableCopy];
for (int i=0; i<PassarrIndexPaths.count; i++)
{
AuditNextTableViewCell *cell = [Audittable cellForRowAtIndexPath:[PassarrIndexPaths objectAtIndex:i]];
DataModel *model = [arrData objectAtIndex:i];
if([model.strSelected isEqualToString:@"P"])
{
}
else if ([model.strSelected isEqualToString:@"W"])
{
}
else if ([model.strSelected isEqualToString:@"F"])
{
}
else if ([model.strSelected isEqualToString:@"NA"])
{
}
else if ([model.strSelected isEqualToString:@"NAA"])
{
}
else
{
model.strSelected = @"PA";
[cell.passbtn setBackgroundColor:[UIColor greenColor]];
[cell.failbtn setBackgroundColor:[UIColor lightGrayColor]];
[cell.wipbtn setBackgroundColor:[UIColor lightGrayColor]];
[cell.nabtn setBackgroundColor:[UIColor lightGrayColor]];
}
のようなコードを使用していますselect.For選択ではないコアデータの配列要素をremaning保存PASS私は問題に直面していますですコアデータにいくつかのデータを保存すれば、それはコアデータにアレイの残存データを保存する方法です。誰かがこのようにしてくれました.Adnavceに感謝します!
あなたは残り何を意味しますかデータ? –
管理オブジェクトモデルを作成し、管理オブジェクトコンテキストを保存します。 – Jitendra
@Mukesh @画像と同様にコアデータに配列から1つの文字列を保存しました。すべてを選択すると、配列の残りのデータを保存する必要があります。最初のインデックスをスキップし、コアデータの配列の他の値を保存します。可能です? – Muju