0

My goal is to ask for two inputs and then divide one by the other. I have textfields that are inputting the two values, an ibaction button and then a uilabel to display the values.

#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

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

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: terminating with uncaught exception of type NSException

What did I do wrong?

Abhineet Verma
  • 1,008
  • 8
  • 18
Akbapu
  • 779
  • 2
  • 6
  • 14

2 Answers2

1

Try changing this:

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

To this:

label.text = [NSString stringWithFormat: @"%f", (inv.text.floatValue / eq.text.floatValue)];
user3344977
  • 3,584
  • 4
  • 32
  • 88
  • I tried that but it didn't change anything. I got the same error again! I'm not sure if just changing the type of input is the solution, but thanks? – Akbapu Jun 25 '14 at 21:18
0

You have an outlet called textf, but the corresponding element has been deleted from the xib/storyboard.

Zev Eisenberg
  • 8,080
  • 5
  • 38
  • 82