我无法创建一种方法来为数据库创建广告和envialo。错误是“setValue:forUndefinedKey:]:此类不是密钥值编码兼容的关键adDescription。”“这只有在重定向我宣布注册视图时才会发生
这是观点记录:
#import "AddAdViewController.h"
#import "Ads.h"
#import "JVWebService.h"
#import "AppDelegate.h"
#import "JVUtils.h"
#import "AdsTableViewController.h"
@interface AddAdViewController () <JVWebServiceDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate, UIPickerViewDelegate>
@property (nonatomic) BOOL show;
@property (strong, nonatomic) UITextField *currentTextField;
@end
@implementation AddAdViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
- (IBAction)addAd:(id)sender {
if (self.adTitleField.text.length <= 0) {
[JVUtils showMessage:@"Você precisa nos informar seu nome completo." withTitle:@"Opa!"];
} else if (self.adPriceField.text.length <= 0) {
[JVUtils showMessage:@"Você precisa nos informar um e-mail para contato." withTitle:@"Opa!"];
} else if (self.adLocalField.text.length <= 0) {
[JVUtils showMessage:@"Você precisa criar uma senha para a sua conta." withTitle:@"Opa!"];
} else if (self.adDescriptionField.text.length <= 0) {
[JVUtils showMessage:@"Você precisa confirmar sua senha." withTitle:@"Opa!"];
} else {
Ads *newAd = [Ads new];
newAd.title = self.adTitleField.text;
newAd.price = self.adPriceField.text;
newAd.local = self.adLocalField.text;
newAd.description = self.adDescriptionField.text;
[[JVWebService sharedService] setServiceDelegate:self];
[[JVWebService sharedService] postAd:newAd];
}
}
#pragma mark - Bar Button Action
- (void)cancelButtonAction {
[self dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark - JVWebService Delegate
- (void)successfulRequestDidReturnObject:(NSObject *)object {
[JVUtils showMessage:@"Agora você tem uma conta JáVendi! Faça o login e desfrute ao máximo do aplicativo." withTitle:@"Parabéns!"];
[[AppDelegate sharedDelegate] setCurrentUser:(User *)object];
[self dismissViewControllerAnimated:YES completion:nil];
AdsTableViewController *svc = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"LoginViewController"];
[self.navigationController presentViewController:[[UINavigationController alloc] initWithRootViewController:svc]
animated:YES
completion:nil];
}
- (void)requestDidFailWithError:(NSError *)error {
[JVUtils showMessage:error.localizedDescription withTitle:@"Erro"];
}
@end
答案 0 :(得分:0)
此错误表示您尝试在没有adDescription属性的对象上设置名为“adDescription”的属性。我没有看到你直接引用这个变量,所以它可能会在你的一个setter中设置,特别是你制作广告的地方,或者这一行
[[AppDelegate sharedDelegate] setCurrentUser:(User *)object];