0

我收到以下错误:

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: 
'[<AddListingViewController 0xe603940> setValue:forUndefinedKey:]: 
this class is not key value coding-compliant for the key listingDescription.'

顺便说一句,listingDescription 在另一个类中,它看起来像这样:

@property (nonatomic, strong) NSString *listingDescription;

这是我的 AddListingViewController.h

    #import <UIKit/UIKit.h>
    #import "ListingTableViewController.h"
    #import "ListingManager.h"
    @interface AddListingViewController : UIViewController
    @property (nonatomic) ListingManager *manager;

    @end

这是 AddListingViewController.m

#import "AddListingViewController.h"

@interface AddListingViewController ()
@property (weak, nonatomic) IBOutlet UITextField *title;
@property (weak, nonatomic) IBOutlet UITextView *description;
@property (weak, nonatomic) IBOutlet UITextField *price;


@end

@implementation AddListingViewController




- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

    //cancel posting on tap
- (IBAction)cancelListing:(UIBarButtonItem *)sender {
    NSLog(@"cancel tapped thpugh");
    [self dismissViewControllerAnimated:YES completion:nil];

}

    //add item on tap
- (IBAction)addListing:(UIBarButtonItem *)sender {
    NSLog(@"Add button tapped");

}

@end

不知道为什么我收到错误。每当我单击条形按钮“添加”以转到“AddListingViewController”视图控制器时,我都会收到错误消息。环顾四周,但他们的答案并不能满足我的需求。

4

2 回答 2

0

不太可能是相关问题,但您在 NSObject 协议的“描述”方法与此之间存在冲突:

@property (weak, nonatomic) IBOutlet UITextView *description;

这可能会在调试/注销类对象时导致问题。

除此之外,我会在您调用“listingDescription”时进行跟踪,或者使用任何与 KVO 相关的机制将其用作键。

于 2014-06-29T23:23:52.527 回答
0

根据上面 nhgrif 的评论环顾四周。文本框引用了另外两件事(之前设置并忘记删除)。傻我。谢谢大家的回答

于 2014-06-30T13:43:02.117 回答