我试图从Parse后端下载图像。它显示"今天的图像"在UITableView的后台,通过创建PFQuery,设置Parse类名称,可选地设置日期(最终版本中的ofc)并查找对象。但是,它给了我一个错误。
// Create a query and set it up to find todays pic
NSLocale *currentLocale = [NSLocale currentLocale];
PFQuery *todayQuery = [PFUser query];
todayQuery = [PFQuery queryWithClassName:@"Today"];
[todayQuery findObjectsInBackgroundWithBlock:^(NSArray *result, NSError *error) {
// Download the image
NSData *imageData;
for (PFObject *object in result) {imageData = [object objectForKey:@"todaysPic"];}
// Use the image
UIImage *todaysPicture = [UIImage imageWithData:imageData];
UIImage *finalTodaysPicture = [[UIImage alloc] init];
finalTodaysPicture = [self blur:todaysPicture];
self.tableView.backgroundColor = [UIColor colorWithPatternImage:finalTodaysPicture];
}];
// Convert to JPEG with 50% quality
NSData* data = UIImageJPEGRepresentation([UIImage imageNamed:@"star.jpg"], 0.5f);
PFFile *imageFile = [PFFile fileWithName:@"Image.jpg" data:data];
这是我的Parse行:
Xcode告诉我:
2014-10-09 19:05:55.496 iStory[1082:4130995] -[PFFile length]: unrecognized selector sent to instance 0x7fd18bc311f0
并
(lldb) bt
* thread #1: tid = 0x3f0cf1, 0x000000010c4d6b8a libobjc.A.dylib`objc_exception_throw, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
frame #0: 0x000000010c4d6b8a libobjc.A.dylib`objc_exception_throw
frame #1: 0x000000010c84450d CoreFoundation`-[NSObject(NSObject) doesNotRecognizeSelector:] + 205
frame #2: 0x000000010c79c7fc CoreFoundation`___forwarding___ + 988
frame #3: 0x000000010c79c398 CoreFoundation`__forwarding_prep_0___ + 120
frame #4: 0x000000010d077559 UIKit`_UIImageRefFromData + 57
frame #5: 0x000000010cedc55f UIKit`-[UIImage(UIImagePrivate) _initWithData:preserveScale:cache:] + 110
frame #6: 0x000000010ced89d1 UIKit`+[UIImage imageWithData:] + 50
* frame #7: 0x000000010ab937cf iStory`__37-[HomeViewController viewWillAppear:]_block_invoke(.block_descriptor=0x00007f94495a3c40, result=0x00007f9449552b80, error=0x0000000000000000) + 655 at HomeViewController.m:70
frame #8: 0x000000010abe0ac7 iStory`__49-[BFTask(.block_descriptor=<unavailable>, task=<unavailable>) thenCallBackOnMainThreadAsync:]_block_invoke + 251 at BFTask+Private.m:59
frame #9: 0x000000010abf91a8 iStory`__41-[BFTask continueWithExecutor:withBlock:]_block_invoke_2(.block_descriptor=0x00007f94495a50d0) + 30 at BFTask.m:287
frame #10: 0x000000010e651cc6 libdispatch.dylib`_dispatch_call_block_and_release + 12
frame #11: 0x000000010e66f7f4 libdispatch.dylib`_dispatch_client_callout + 8
frame #12: 0x000000010e658991 libdispatch.dylib`_dispatch_main_queue_callback_4CF + 956
frame #13: 0x000000010c7a5569 CoreFoundation`__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
frame #14: 0x000000010c76846b CoreFoundation`__CFRunLoopRun + 2043
frame #15: 0x000000010c767a06 CoreFoundation`CFRunLoopRunSpecific + 470
frame #16: 0x000000010ff409f0 GraphicsServices`GSEventRunModal + 161
frame #17: 0x000000010cea6550 UIKit`UIApplicationMain + 1282
frame #18: 0x000000010ab928a3 iStory`main(argc=1, argv=0x00007fff55077370) + 115 at main.m:14
frame #19: 0x000000010e6a4145 libdyld.dylib`start + 1
(lldb)
非常感谢帮助!
谢谢!
此致 埃里克
答案 0 :(得分:0)
我这样修好了:
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:YES];
// Create a query and set it up to find todays pic
NSLocale *currentLocale = [NSLocale currentLocale];
PFQuery *todayQuery = [PFUser query];
todayQuery = [PFQuery queryWithClassName:@"Today"];
[todayQuery findObjectsInBackgroundWithBlock:^(NSArray *result, NSError *error) {
// Download the image
NSData *imageData;
PFObject *imageObject;
for (imageObject in result) {
PFFile *imageFile = (PFFile *)[imageObject objectForKey:@"todaysPic"];
[imageFile getDataInBackgroundWithBlock:^(NSData *resultData, NSError *error ) {
if (!error) {
// Create and set the image
UIImage *todaysImage = [UIImage imageWithData:resultData];
UIImage *blurredTodaysImage = [self blur:todaysImage];
self.tableView.backgroundColor = [UIColor colorWithPatternImage:blurredTodaysImage ];
} else {
// Just set a default picture
}
}];
}
}];