2013-04-17 3 views
0

NSFetchedResultsController 및 주 컨텍스트가 첨부 된 UITableView가 있습니다. 백그라운드에서 주 컨텍스트를 업데이트 중입니다. 새로운 데이터 및 모든 것에코어 데이터 가져 오기 속성. 업데이트 후 새로 고침

- (void)contextDidSave:(NSNotification *)notification 
{ 
    NSManagedObjectContext *context=[self managedObjectContext]; 
    [context performSelectorOnMainThread:@selector(mergeChangesFromContextDidSaveNotification:) withObject:notification waitUntilDone:YES]; 

    if ([context hasChanges]) 
    {    
     [context performSelectorOnMainThread:@selector(save:) withObject:nil waitUntilDone:YES]; 

    }   
} 

내 jQuery과 다시로드는 하지만 일부 jQuery과 셀의 데이터를 가져올 호텔이 채워 져야합니다 잘 내가 값을 새로 고칠 수 있다고합니다.

NSManagedObjectContext의 refreshObject : mergeChanges : 메소드에 대해 읽었습니다. 도움이 될 것입니다. 어디에서 배치해야합니까? cellForRowAtIndexPath의 도우미 메소드 - configureCell : atIndexPath에 배치하면 사이클 업데이트 행이 생성됩니다.

- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)theIndexPath 
{ 
    //NSLog(@"PTAgencyList: configureCell: atIndexPath: %i %i", theIndexPath.section, theIndexPath.row); 

    NSManagedObject *managedObj=[self.agenciesFetchedResultsController objectAtIndexPath:theIndexPath]; 
    if (managedObj==nil) 
    { 
     NSLog(@"PANIC: fetchedResultsController objectAtIndexPath: returned nil object"); 
     return; 
    } 
    else 
    { 

     CDAgency *agency=(CDAgency *)managedObj; 

     [agency city]; 
     NSLog(@"agency.city_server_id: %@", agency.city_server_id); 
     NSLog(@"agency.city.name: %@", ((CDCities *)[[agency city] objectAtIndex:0]).name); 
     NSFetchRequest *fr=[[NSFetchRequest alloc] init]; 
     [fr setEntity:[NSEntityDescription entityForName:@"Cities" inManagedObjectContext:self.context]]; 
     [fr setPredicate:[NSPredicate predicateWithFormat:@"server_id=%@", agency.city_server_id]]; 
     NSArray *res=[self.context executeFetchRequest:fr error:nil]; 
     NSLog(@"fetched city name: %@", ((CDCities *)[res objectAtIndex:0]).name); 

상황에 맞는 업데이트 후 : 여기

셀 구성 코드의 조각이다 가져온 재산 도시 (나는 여전히 제거 된 오래된 도시 엔트리를 가리키는 때문입니다 생각) 무기 호입니다, 하지만, 가져 오기를 수동으로 수행하는 경우 신선한 데이터가 나타납니다.

답변

1

셀을 구성 할 때 가져온 속성을 명시 적으로 호출하면됩니다.

[managedObject fetchedPropertyAttribute]; 

예상대로 재 계산해야합니다.

또한 가져온 속성 대신관계를 사용하는 것이 좋습니다.

+0

작동하지 않습니다. 내 대답을 편집했습니다. – user1897723

+0

질문이 있으시면 언제든지 문의하십시오. – user1897723

+0

구성 셀에서 가져 오기 요청이 거의 확실하게 잘못되었습니다. 가져온 결과 컨트롤러에서 반환 한 개체를 사용해야합니다. – Mundi

관련 문제