Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

WhatsACode

macrumors newbie
Original poster
Jul 3, 2014
4
0
Hi!
I`m extremely new to programming in general, and I can't figure out this error. In the debugging area, it says

"*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<FirstViewController 0x109339890> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key CalculateButton.'"

If anyone could help, I would really appreciate it.
 
I have an IBAction listed in my code and the button is still linked to it.
https://drive.google.com/file/d/0B2nHSI6_HBAuMmRmRzRPdjNZU0E/edit?usp=sharing

Here is my FirstViewController.h
Code:
#import <UIKit/UIKit.h>

@interface FirstViewController : UIViewController {
    
    __weak IBOutlet UITextField *TextField1;
    __weak IBOutlet UITextField *TextField2;
    __weak IBOutlet UITextField *TextField3;
    __weak IBOutlet UILabel *GradeNeeded;
}
- (IBAction)CalculateButton:(id)sender;


@end
and my FirstViewController.m

Code:
#import "FirstViewController.h"

@interface FirstViewController ()

@end

@implementation FirstViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
   
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)CalculateButton:(id)sender {
    
    float x = ([TextField1.text floatValue]);
    
    float y = ([TextField2.text floatValue]);
    
    float z = ([TextField3.text floatValue]);
    
    float answer = ((y)-(x*(1-z)))/z;
    
    GradeNeeded.text = [[NSString alloc] initWithFormat:@"%2.f"
                        
                        ,answer];
}
@end

Does it need to be changed to an IBOutlet?
 
Last edited by a moderator:
Look at the connections in your nib. There is something wrong with the connection to that action. You may need to remove what's there and re-add it.

The error message says that when trying to connect an outlet named CalculateButton that outlet didn't exist. You're right that it's an action not an outlet. For some reason it thinks you told it that there is an outlet of that name.

BTW, use the code tag, not the quote tag for code. That's the button with the #. Then you won't get the unhappy faces in your code :(
 
I figured it out. I had some duplicate connections or something like that with multiple names. Thank you so much PhoneyDeveloper for your help!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.