我推一个视图控制器,然后当我通过一个段控制器弹出它回到原来的。一些值将会改变。一个是距离值(浮点数),另一个是存储为二进制数据的缩略图。推送ViewController和弹出会导致核心数据对象丢失值
有没有办法告诉核心数据基本上冻结这个数组(它当前是一个数组),然后它推动另一个视图控制器?也许把它复制到一个tmpArray,然后将其拷贝回viewDidAppear上的tmpArray是否存在?听起来很不好,但我需要得到这个工作。
THX
编辑#1
因此,这里是哪里左右出问题一些代码。因此,它似乎像getAllLocationsWithFinished是导致self.tmpLocations改变:
//works
NSLog(@"#1 locations right before call: %@",[self.locations objectAtIndex:2]);
self.tmpLocations=[[NSArray alloc] initWithArray:[self.locations copy]];
//works
NSLog(@"#2 locations right before call: %@",[self.tmpLocations objectAtIndex:2]);
[[ModelManager sharedModelManager] getAllLocationsWithFinished:^(NSArray* map_locations)
{
// data is off
NSLog(@"#3 locations right before call: %@",[self.tmpLocations objectAtIndex:2]);
您确定'getAllLocationsWithFinished'回调方法在主线程上被调用吗?你的'tmpLocations'属性是如何声明的?强大?在块运行之前以及在为属性指定位置数组后,请尝试以下操作:'__block NSArray * testArray = self.tmpLocations;'然后NSLog块中的'* testArray'。 – Rog
tmpLocations强度很强。在后台线程上getAllLocationsWithFinished将运行。当我NSLog的testArray距离和defaultImageData都是零。其他值设置正确 – timpone