用于分割整数的NSUnknownKeyException?

时间:2014-06-25 20:21:36

标签: ios objective-c xcode nsunknownkeyexception

我的目标是要求两个输入,然后将一个输入除以另一个输入。我有输入两个值的文本字段,一个ibaction按钮,然后是uilabel来显示值。

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
@synthesize label, inv, eq;

- (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)sub:(id)sender {

    label.text = [NSString stringWithFormat: @"%i", (inv.text.intValue / eq.text.intValue)];
}
@end

错误是由于未捕获的异常终止应用程序' NSUnknownKeyException',原因:' [setValue:forUndefinedKey:]:此类不是键值textf的键值编码兼容。&# 39;

First throw call stack:
(
    0   CoreFoundation                      0x017ec1e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x0156b8e5 objc_exception_throw + 44
    2   CoreFoundation                      0x0187bfe1 -[NSException raise] + 17
    3   Foundation                          0x0122bd9e -[NSObject(NSKeyValueCoding) setValue:forUndefinedKey:] + 282
    4   Foundation                          0x011981d7 _NSSetUsingKeyValueSetter + 88
    5   Foundation                          0x01197731 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 267
    6   Foundation                          0x011f9b0a -[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 412
    7   UIKit                               0x004e21f4 -[UIRuntimeOutletConnection connect] + 106
    8   libobjc.A.dylib                     0x0157d7de -[NSObject performSelector:] + 62
    9   CoreFoundation                      0x017e776a -[NSArray makeObjectsPerformSelector:] + 314
    10  UIKit                               0x004e0d4d -[UINib instantiateWithOwner:options:] + 1417
    11  UIKit                               0x003496f5 -[UIViewController _loadViewFromNibNamed:bundle:] + 280
    12  UIKit                               0x00349e9d -[UIViewController loadView] + 302
    13  UIKit                               0x0034a0d3 -[UIViewController loadViewIfRequired] + 78
    14  UIKit                               0x0034a5d9 -[UIViewController view] + 35
    15  UIKit                               0x0026a267 -[UIWindow addRootViewControllerViewIfPossible] + 66
    16  UIKit                               0x0026a5ef -[UIWindow _setHidden:forced:] + 312
    17  UIKit                               0x0026a86b -[UIWindow _orderFrontWithoutMakingKey] + 49
    18  UIKit                               0x002753c8 -[UIWindow makeKeyAndVisible] + 65
    19  UIKit                               0x00225bc0 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 2097
    20  UIKit                               0x0022a667 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 824
    21  UIKit                               0x0023ef92 -[UIApplication handleEvent:withNewEvent:] + 3517
    22  UIKit                               0x0023f555 -[UIApplication sendEvent:] + 85
    23  UIKit                               0x0022c250 _UIApplicationHandleEvent + 683
    24  GraphicsServices                    0x037e1f02 _PurpleEventCallback + 776
    25  GraphicsServices                    0x037e1a0d PurpleEventCallback + 46
    26  CoreFoundation                      0x01767ca5 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
    27  CoreFoundation                      0x017679db __CFRunLoopDoSource1 + 523
    28  CoreFoundation                      0x0179268c __CFRunLoopRun + 2156
    29  CoreFoundation                      0x017919d3 CFRunLoopRunSpecific + 467
    30  CoreFoundation                      0x017917eb CFRunLoopRunInMode + 123
    31  UIKit                               0x00229d9c -[UIApplication _run] + 840
    32  UIKit                               0x0022bf9b UIApplicationMain + 1225
    33  Investmentts                        0x00002fad main + 141
    34  libdyld.dylib                       0x01e33701 start + 1
    35  ???                                 0x00000001 0x0 + 1
)

libc ++ abi.dylib:以NSException类型的未捕获异常终止

我做错了什么?

2 个答案:

答案 0 :(得分:1)

尝试更改此内容:

label.text = [NSString stringWithFormat: @"%i", (inv.text.intValue / eq.text.intValue)];

对此:

label.text = [NSString stringWithFormat: @"%f", (inv.text.floatValue / eq.text.floatValue)];

答案 1 :(得分:0)

您有一个名为textf的商店,但相应的元素已从xib / storyboard中删除。