我正在尝试将数据从一个 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 的键值编码不兼容。”
我只是想将两个字符串从一个屏幕传回另一个屏幕。我该如何解决这个问题?