0

我正在尝试将数据从一个 Table View Controller 传递回它之前的一个。这是我为完成它而编写的代码: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

内部选项卡视图控制器.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 的键值编码不兼容。”

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

4

1 回答 1

0

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

由于您只需要字符串,因此我建议您重新设计协议

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

更简单的东西

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

不知道能不能解决问题。如果我有你的完整代码,我可以提供帮助。

于 2013-05-29T19:01:33.140 回答