增加委托传递数据,现在抛出错误类不是关键值编码兼容?

问题描述:

我正试图将数据从一个表视图控制器传回给它之前的那个。这里是我写来完成它的代码: NPViewController.h(第二视图通过数据回):增加委托传递数据,现在抛出错误类不是关键值编码兼容?

@class NPViewController; 

@protocol NPViewControllerDelegate <NSObject> 

-(void) passItemBack: (NPViewController *) controller didFinishWithItem: (NSString *) string; 

@end 

@interface NPViewController : UITableViewController <UITextFieldDelegate> 
@property (weak, nonatomic) id<NPViewControllerDelegate> delagate; 

- (IBAction)createNewProject:(id)sender; //a bar button item that sends data on click 
@end 

NPViewController.m:

//barButton item IBAction 
- (IBAction)createNewProject:(id)sender { 
    [self.delagate passItemBack:self didFinishWithItem:@"Test"]; 
    [self dismissViewControllerAnimated:YES completion:nil]; 
} 

InternalTabViewController.h //第一视图对收到的数据

#import <UIKit/UIKit.h> 
#import "NPViewController.h" 


@interface InternalTabViewController : UITableViewController <NPViewControllerDelegate> 
@property (weak, nonatomic) NSString * projectName; 
@property (weak, nonatomic) NSString * projectWorth; 
@end 

InternalTabViewController.m

@synthesize projectName, projectWorth; 

//in ViewDidLoad 
NPViewController *NPVC = [self.storyboard instantiateViewControllerWithIdentifier:@"NPViewController"]; 
NPVC.delagate = self; 

//implementation of protocol function 
-(void)passItemBack:(NPViewController *)controller didFinishWithItem:(NSString *)string 
{ 
    self.projectName = string; 
} 

程序无法得到过去的第一视图控制器(无关这两个),并引发错误:

终止应用程序由于未捕获的异常“NSUnknownKeyException”,原因:“[setValue方法:forUndefinedKey:]:这个类不是密钥createNewProject的关键值编码。“

我只是想将两个字符串从一个屏幕传回另一个屏幕。我该如何解决这个问题?

+0

你可以在IB或故事板检查你的IBAction createNewProject连接吗?当然http://*.com/questions/5109309/this-class-is-not-key-value-coding-compliant-for-the-key-authview –

+0

。他们连接。它表示它已连接发送操作和引用网点。 – DCIndieDev

+0

检查你的按钮引用插座,在你的代码中你没有任何IBOutlet是一个酒吧按钮。您只是将按钮的动作与IBACtion相关联,但您没有设置IBOutlet。 – danypata

我不明白你为什么要将NPViewController(ViewController)传递给InternalTabViewController(ViewController)并且稍后关闭它(dismissViewControllerAnimated)。

当你只需要字符串我会建议重新设计协议

-(void) passItemBack: (NPViewController *) controller didFinishWithItem: (NSString *) string; 

以更简单的东西

-(void) passItemBack:(NSString*) item; 

我不知道这是否会解决问题。如果我有你的完整代码,我可以帮忙。