2013-10-15 6 views
0

Мне нужно обновить значение нужной ячейки в моих основных данных. У меня есть ячейка (ID) с известным значением для меня. Мне нужно найти значение и заменить его. Я знаю, как изменить элементы массива. Ниже показано, как я это делаю. Но мне нужно изменить поле (ID) в MyBase. значение, которое мне нужно изменить, будет равнозначению fromIndexPath.row. Значение, на которое мне нужно изменить toIndexPath.row.Обновление данных ядра ядра

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath 
                  *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { 
if (fromIndexPath.section == toIndexPath.section) { 

    NSFetchRequest* fetchRequest = [[NSFetchRequest alloc] init]; 
    NSEntityDescription* entityDescription = [NSEntityDescription entityForName:@"MyBase" 
                 inManagedObjectContext:self.objectContext]; 
    [fetchRequest setEntity:entityDescription]; 

    empArray = [(NSArray*)[self.objectContext executeFetchRequest:fetchRequest error:nil] mutableCopy]; 

    MyBase *employee = [empArray objectAtIndex:fromIndexPath.row]; 

     [empArray removeObjectAtIndex:fromIndexPath.row]; 
     [empArray insertObject:objectToMove atIndex:toIndexPath.row]; 
} 

}

ответ

0

для основного обновления данных, вы можете попробовать это:

NSFetchRequest *request = [[NSFetchRequest alloc] init]; 
NSEntityDescription *entity = [NSEntityDescription entityForName:@:@"Employee"  
              inManagedObjectContext:self.managedObjectContext]; 
[request setEntity:entity]; 

NSPredicate *pred = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"empId = %d", 12345]]; 
[request setPredicate:pred]; 

NSArray *empArray=[self.managedObjectContext executeFetchRequest:request error:nil]; 
[request release]; 

if ([empArray count] > 0){ 
    Employee *employee = [empArray objectAtIndex:fromIndexPath.row];; 

    employee.empSalary=[NSNumber numberWithInt:45000]; 

    [email protected]"John"; 
    [email protected]"Analysist"; 
    [email protected]"4 Years"; 

    [self.managedObjectContext save:nil]; 
Смежные вопросы