核心数据iCloud提取有时不会产生数据(iOS)
问题描述:
我在使用iCloud Core Data的测试应用程序中遇到问题。触摸表格视图中的部分条目时会触发特定的问题,触发全屏幕表格全屏显示。一种标准的表格视图的东西。核心数据iCloud提取有时不会产生数据(iOS)
表视图单元格包含传递到详细显示视图的唯一记录标识。在启动视图后,视图控制器get使用完整的记录数据并将其绘制在屏幕上。
这里是用来做什么的代码:
- (void)viewDidLoad {
[super viewDidLoad];
NSString *temp_text;
Item *fetchSelectedItem;
NSString *updateUniqueID;
NSArray *tempFetchedObjects;
NSError *error;
int stopper;
localFindItDataController = [[FindItDataController alloc] init];
NSFetchRequest *fetch = [[NSFetchRequest alloc] init];
NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"Item" inManagedObjectContext: localFindItDataController.managedObjectContext];
[fetch setEntity:entityDescription];
updateUniqueID = [localItem.itemUniqueID stringValue];
[fetch setPredicate:[NSPredicate predicateWithFormat:@"(ANY itemUniqueID = %@)",updateUniqueID]];
tempFetchedObjects = [localFindItDataController.managedObjectContext executeFetchRequest:fetch error:&error];
NSLog(@"did the fetch work %@ %lu", updateUniqueID, (unsigned long)[tempFetchedObjects count]);
if ([tempFetchedObjects count] == 0) {
stopper = 1;}
fetchSelectedItem = [tempFetchedObjects objectAtIndex:0];
NSLog(@"only executes if fetch was ok");
localItem = fetchSelectedItem;
temp_text = localItem.itemName;
contentsWhatBox.text = temp_text;
temp_text = localItem.itemLocation;
contentsWhereBox.text = temp_text;
temp_text = localItem.itemDescription;
contentsOtherInfoBox.text = temp_text;
UIImage *tempImage = [UIImage imageWithData:localItem.itemPicture];
CGImageRef imageRef = [self CGImageRotatedByAngle:[tempImage CGImage] angle:270];
UIImage* img = [UIImage imageWithCGImage: imageRef];
contentsImageBox.image = img;
tapImage = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImageGesture)];
[contentsImageBox setUserInteractionEnabled:YES];
[contentsImageBox addGestureRecognizer:tapImage];
}
晴这工作得很好,但偶尔抓取出现空,即使存在肯定的是,取谓词相匹配的数据。有时我可以点击表格视图条目,看到它出现,在表格视图条目之间来回几次,返回到原始条目,并且提取失败。
我有些茫然,任何帮助都会受到欢迎。提前致谢。
编辑#1:
这是正在提取的对象。也许无关紧要,所以我说这在以后:
@interface Item : NSManagedObject {
}
@property (nonatomic, retain) NSString * itemName;
@property (nonatomic, retain) NSString * itemLocation;
@property (nonatomic, retain) NSString * itemDescription;
@property (nonatomic, retain) NSData * itemPicture;
@property (nonatomic, retain) NSNumber * itemUniqueID;
@property (nonatomic, retain) NSNumber * itemNumber1;
@property (nonatomic, retain) NSNumber * itemNumber2;
@property (nonatomic, retain) NSString * itemAttribute1;
@property (nonatomic, retain) NSString * itemAttribute2;
@property (nonatomic, retain) NSString * itemAttribute3;
@property (nonatomic, retain) NSString * itemTimestamp;
@end
编辑#2:
我忘了提,从获取错误对象是后“坏”取零。
编辑#3:
增加了一个循环来检查,如果我得到一个结果,然后重试一定次数,在退出前和工作确定。我不确定它为什么会发生,但我怀疑iCloud数据中的图像可能是问题的一部分,即使此时的数据肯定会被复制到iOS测试设备。
答
增加了一个循环来检查我是否得到了一个结果,并在退出之前重试了一定次数并且工作正常。我不确定它为什么会发生,但我怀疑iCloud数据中的图像可能是问题的一部分,即使此时的数据肯定会被复制到iOS测试设备。