【发布时间】:2015-11-03 03:02:39
【问题描述】:
我有一个应用程序保存要解析的图像,它由第一个 VC 中的集合视图和一个详细视图控制器组成,您可以在其中通过 UIImagePickerController 添加图片。我之前在 Objective-C 中使用过 parse,但一直收到此错误
[PFObject setPhoto:]: unrecognized selector sent to instance 0x7fa15ac8f1c0
我在项目中有一个带有属性的解析类,我知道有不同的方法,但我通常这样做并且没有任何问题。
解析类头文件
#import <Parse/Parse.h>
@interface Picture : PFObject <PFSubclassing>
@property (nonatomic, strong) NSString *Caption;
@property (nonatomic, strong) NSArray *Likes;
@property (nonatomic, strong) PFFile *Photo;
+ (NSString *)parseClassName;
@end
.m 文件
#import "Picture.h"
static NSString * const ClassName = @"Picture";
@implementation Picture
@dynamic Caption;
@dynamic Likes;
@dynamic Photo;
+ (NSString *)parseClassName {
return ClassName;
}
@end
这是我保存图片的地方
- (IBAction)saveImage:(id)sender {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Add caption" message:nil preferredStyle:UIAlertControllerStyleAlert];
[alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.placeholder = @"title";
}];
[alertController addAction:[UIAlertAction actionWithTitle:@"Save" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSArray *textFields = [alertController textFields];
NSString *nameString = ((UITextField *)textFields[0]).text;
NSData *imageData = UIImagePNGRepresentation(self.chosenImage);
// PFObject *object = [PFObject objectWithClassName:@"Picture"];
Picture *picture = [Picture object];
PFFile *file = [PFFile fileWithData:imageData];
[picture saveInBackgroundWithBlock:^(BOOL succeeded, NSError * _Nullable error) {
if (succeeded) {
picture.Photo = file;
picture.Caption = nameString;
[picture saveInBackground];
[picture pinInBackground];
UIAlertController *successAlert = [UIAlertController alertControllerWithTitle:@"Photo Saved!" message:nil preferredStyle:UIAlertControllerStyleAlert];
[successAlert addAction:[UIAlertAction actionWithTitle:@"Okay" style:UIAlertActionStyleCancel handler:nil]];
[self presentViewController:successAlert animated:YES completion:nil];
}
else {
NSLog(@"%@", error.localizedDescription);
}
}];
[alertController addAction:[UIAlertAction actionWithTitle:@"Okay!" style:UIAlertActionStyleCancel handler:nil]];
//save to parse here
}]];
[self presentViewController:alertController animated:YES completion:nil];
}
//image picker delegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info {
self.chosenImage = info[UIImagePickerControllerEditedImage];
self.imageView.image = self.chosenImage;
[picker dismissViewControllerAnimated:YES completion:nil];
}
起初我以为这可能是图像的大小,但是当我注释掉该部分并尝试保存标题时,我得到了同样的错误,但使用的是“setCaption”而不是“setPhoto”
更新:对象已保存以进行解析,但列中没有数据,键(属性)拼写正确,所有内容也是如此。
谢谢!
【问题讨论】:
标签: objective-c parse-platform ios9