基本上遵循本教程https://parse.com/tutorials/saving-images。当用户点击一个图像时,它会带他们到一个新的视图控制器并全屏显示这个图像。当我点击图片时,它会把我带到一个黑屏,并抛出以下错误
Warning: A long-running Parse operation is being executed on the main thread.
Break on warnParseOperationOnMainThread() to debug.
我检查过了,它将图片发送到新的视图控制器所以它可能与VC本身有关。我在它要求我的地方放了一个断点,下面是线程说的
`My App`warnParseOperationOnMainThread at PFTask.m:15:
0x95fa0: pushl %ebp
0x95fa1: movl %esp, %ebp
0x95fa3: subl $0x8, %esp
0x95fa6: calll 0x95fab ; warnParseOperationOnMainThread + 11 at PFTask.m:15
0x95fab: popl %eax
0x95fac: leal 0x18771d(%eax), %eax
0x95fb2: movl %eax, (%esp)
0x95fb5: calll 0x98d54 ; symbol stub for: NSLog
0x95fba: addl $0x8, %esp
0x95fbd: popl %ebp
0x95fbe: retl
第五个线程指向我的一个类中的一个名为buttonTouched的方法。它指向这行代码:
imageData = [theImage getData];
方法如下:
- (void)buttonTouched:(id)sender {
// When picture is touched, open a viewcontroller with the image
PFObject *theObject = (PFObject *)[allImages objectAtIndex:[sender tag]];
PFFile *theImage = [theObject objectForKey:@"imageFile"];
NSData *imageData = [[NSData alloc] init];
imageData = [theImage getData];
UIImage *selectedPhoto = [UIImage imageWithData:imageData];
PhotoDetailViewController *pdvc = [[PhotoDetailViewController alloc] init];
pdvc.selectedImage = selectedPhoto;
[self presentViewController:pdvc animated:YES completion:nil];
NSLog(@"Photo controller %@", pdvc.selectedImage);
}
快把我逼疯了。一切几乎都是相同的教程。还是需要定义到2vc的segue关系?如果相关的话,我会使用故事板。
一个很好的解释这是怎么发生的和一个解决方案将是很棒的。
出现警告是因为您正在主线程中下载图像。您可以在后台下载它,并在下载完成后呈现视图,如下所示。
- (void)buttonTouched:(id)sender {
// When picture is touched, open a viewcontroller with the image
PFObject *theObject = (PFObject *)[allImages objectAtIndex:[sender tag]];
PFFile *theImage = [theObject objectForKey:@"imageFile"];
[theImage getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
UIImage *selectedPhoto = [UIImage imageWithData:imageData];
PhotoDetailViewController *pdvc = [[PhotoDetailViewController alloc] init];
pdvc.selectedImage = selectedPhoto;
[self presentViewController:pdvc animated:YES completion:nil];
NSLog(@"Photo controller %@", pdvc.selectedImage);
}];
}
另一种解决这个问题的方法是,你可以将PFObject传递给呈现的视图,并在加载后下载该视图上的图片。