0

I am attempting to pass data back from one Table View Controller to the one before it. Here is the code I have written to accomplish it: NPViewController.h (The second view passing data back):

@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 //the first view to recieve data

#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;
}

The program cannot get past the first view controller (unrelated to these two) and throws the error:

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key createNewProject.'

I'm just trying to pass two strings back from one screen to another. How do I resolve this?

TestinginProd
  • 1,085
  • 1
  • 15
  • 35
  • Could you check your IBAction createNewProject connection in the IB or storyboard? http://stackoverflow.com/questions/5109309/this-class-is-not-key-value-coding-compliant-for-the-key-authview – Valent Richie May 29 '13 at 17:05
  • of course. They're connected. It says its connected for sent actions and referencing outlets. – TestinginProd May 29 '13 at 18:12
  • Check your button referencing outlets, in your code you don't have any IBOutlet that is a bar button. You just linked the action of the button to the an IBACtion but you didn't set the IBOutlet. – danypata May 29 '13 at 20:15

1 Answers1

0

I cannot understand why you are passing NPViewController (ViewController) to InternalTabViewController(ViewController) and moment later you dismiss it ( dismissViewControllerAnimated).

As you need only string i would recommend redesigning protocol

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

to something simpler

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

I don't know if it will solve problem. If I would have your full code I could help.

BlueConga
  • 887
  • 9
  • 19