핵심 데이터 엔티티에 새 객체를 추가 할 때 내 객체에 애니메이션이 적용되지 않습니다. 많은 것을 시도하고 내 if 문의 정수가 추가되어 managedObject에 변경 사항이 있는지 확인한 다음 if 문으로 이동합니다. 다소 나중에 reloadData를 호출 할 수 있으며 누락 된 셀을 tableview에 넣을 수 있지만 물론 애니메이션으로 처리하려고합니다.managedObject에 새 관계 객체가 저장되지 않음 UITableView에 애니메이션이 적용되지 않습니다.
정확히 insertRow 메서드를 넣어야합니까? 많은 점을 시도했지만 아직 업데이트가 끝나고 나중에 5 번째 행을 추가하려고하는 중 오류가 발생합니다.
- (void)insertNewObject
{
int count = [self.detailItem.catRelations count];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^(void)
{
NSManagedObjectContext *context = self.managedObjectContext;
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Image" inManagedObjectContext:self.managedObjectContext];
newManagedObject = [NSEntityDescription insertNewObjectForEntityForName:[entity name] inManagedObjectContext:context];
[newManagedObject setImageMetaData:localImageMetaData];
[newManagedObject setImageItself:localImageItself];
[newManagedObject setImageCreationDate:[NSDate date]];
[newManagedObject setImageName:localImageTitle];
newManagedObject.imageRelations = self.detailItem;
// Save the context.
NSError *error = nil;
if (![context save:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
dispatch_sync(dispatch_get_main_queue(), ^(void)
{
if (count != self.detailItem.catRelations.count)
{
NSIndexPath *path = [NSIndexPath indexPathForRow:count+1 inSection:0];
[imagesTV insertRowsAtIndexPaths:@[path] withRowAnimation:UITableViewRowAnimationLeft];
}
});
});
두 점 모두 +1! –