当我按下链接到此视图的按钮时出现以下错误。为什么?
2012-12-09 18:44:52.634 LNG[42719:c07] Unknown class DensityViewController in Interface Builder file.
2012-12-09 18:44:52.645 LNG[42719:c07] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x71bcb90> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key ethaneText.'
*** First throw call stack:
(0x1c93012 0x10d0e7e 0x1d1bfb1 0xb7d711 0xafeec8 0xafe9b7 0xb29428 0x2350cc 0x10e4663 0x1c8e45a 0x233bcf 0xf8e37 0xf9418 0xf9648 0xf9882 0x105235 0x3043d2 0x1024f3 0x102777 0x1027b7 0x46dfe2 0x45fad9 0x45fb54 0x10e4705 0x1b920 0x1b8b8 0xdc671 0xdcbcf 0xdbd38 0x4b33f 0x4b552 0x293aa 0x1acf8 0x1beedf9 0x1beead0 0x1c08bf5 0x1c08962 0x1c39bb6 0x1c38f44 0x1c38e1b 0x1bed7e3 0x1bed668 0x1865c 0x2c1d 0x2b45)
libc++abi.dylib: terminate called throwing an exception
(lldb)
densityViewController.h:
#import <UIKit/UIKit.h>
#import "FlipsideViewController.h"
#import "MainViewController.h"
@interface DensityViewController : UIViewController
[More code]
和densityViewController.m
#import "DensityViewController.h"
@interface DensityViewController ()
@end
@implementation DensityViewController
[More code]
最后是我的XIB图片(IK看起来很糟糕,WIP)
我该怎么做才能纠正这个错误? 编辑:完整.m
#import "DensityViewController.h"
@interface DensityViewController()
@end
@implementation DensityViewController
@synthesize tempratureText, methaneText, ethaneText, propaneText, nbutaneText, ibutaneText,npetaneText, ipetaneText, nhexaneText, nitrogenText, oxygenText, outputText;
- (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)textFieldReturn:(id)sender
{
[sender resignFirstResponder];
}
-(IBAction)backgroundTouched:(id)sender
{
[tempratureText resignFirstResponder];
[methaneText resignFirstResponder];
[ethaneText resignFirstResponder];
[propaneText resignFirstResponder];
[nbutaneText resignFirstResponder];
[ibutaneText resignFirstResponder];
[npetaneText resignFirstResponder];
[ipetaneText resignFirstResponder];
[nhexaneText resignFirstResponder];
[oxygenText resignFirstResponder];
[nitrogenText resignFirstResponder];
}
- (void)updateConversionLabel:(UITextField *)textField
{
NSNumberFormatter *fmt1 = [NSNumberFormatter new]; //Temp
NSNumberFormatter *fmt2 = [NSNumberFormatter new]; //Methane
NSNumberFormatter *fmt3 = [NSNumberFormatter new]; //Ethane
NSNumberFormatter *fmt4 = [NSNumberFormatter new]; //Propane
NSNumberFormatter *fmt5 = [NSNumberFormatter new]; //n-butane
NSNumberFormatter *fmt6 = [NSNumberFormatter new]; //i-butane
NSNumberFormatter *fmt7 = [NSNumberFormatter new]; //n-petane
NSNumberFormatter *fmt8 = [NSNumberFormatter new]; //i-petane
NSNumberFormatter *fmt9 = [NSNumberFormatter new]; //n-hexane
NSNumberFormatter *fmt10 = [NSNumberFormatter new]; //nitrogen
NSNumberFormatter *fmt11 = [NSNumberFormatter new]; //oxygen
double temprature = [fmt1 numberFromString:tempratureText.text].doubleValue;
double methane = [fmt2 numberFromString:methaneText.text ].doubleValue;
double ethane = [fmt3 numberFromString:ethaneText.text ].doubleValue;
double propane = [fmt4 numberFromString:propaneText.text ].doubleValue;
double nbutane = [fmt5 numberFromString:nbutaneText.text ].doubleValue;
double ibutane = [fmt6 numberFromString:ibutaneText.text ].doubleValue;
double npetane = [fmt7 numberFromString:npetaneText.text ].doubleValue;
double ipetane = [fmt8 numberFromString:ipetaneText.text ].doubleValue;
double nhexane = [fmt9 numberFromString:nhexaneText.text ].doubleValue;
double nitrogen = [fmt10 numberFromString:nitrogenText.text ].doubleValue;
double oxygen = [fmt11 numberFromString:oxygenText.text ].doubleValue;
double Xi = 1;
double Mi = 2;
double Vi = 3;
double Vc = 4;
//Do not mind this, just placeholders for some other stuffs.
double over1 = Xi * Mi;
double under1 = Xi * Vi - Vc;
double result = over1 / under1;
NSString *resultString = [[NSString alloc]initWithFormat:@" Test %f", result];
/*
outputText.text = resultString;
*/
if (temprature == 0 || methane == 0 || ethane == 0 || propane == 0 || nbutane == 0 || ibutane == 0 || oxygen == 0 || npetane == 0 || ipetane == 0 || nhexane == 0 || nitrogen == 0)
{
outputText.text = @"Please enter all values";
} else
{
outputText.text = resultString;
}
}
@end
答案 0 :(得分:0)
尝试删除界面中的nibe并再次从头开始。因为您可能正在从其他项目复制nib,有时xcode会以这种方式运行。它肯定会起作用。