开发者

Simple functions giving me a crash on Objective-C

I'm coding a simple calculator and I want to make an unique function for all 4 arithmetic buttons. I got here:

-(IBAction)simbolo1:(UIButton*)sender{

    if (isNumeric(campo1.text)) {

        NSString *str=campo1.text;
        campo2.text=str;
        int S=1;
        NSString *cmp1 = [NSString stringWithFormat:@"%d", S];
        sinal.text=cmp1;
        campo1.text=@"";

    } else {

        campo1.text=@"Only numeric values";
    }
}

But, for some reason, I cant get this to work. Everytime I click in the button, I get a crash. So, I check where really was the error and I deleted the whole code:

-(void)simbolo1:(UIButton*)sender{

    campo1.text=@"Only numeric values";
}

Those lines of code appear to gave me the same error as before

I'm getting a 'green :marker' on this file:

#import <UIKit/UIKit.h>

int main(int argc, char *argv[]){
     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
     int retVal = UIApplicationMain(argc, argv, nil, nil);   <--------- This line right here
     [pool release];
     return retVal;
}

EDIT--------------- On the debud console im getting this:

2011-09-30 09:17:14.319 Teste iPhone[28432:fb03] Applications are expected to have a root view controller at the end of application launch
2011-09-30 09:17:21.714 Teste iPhone[28432:fb03] -[Teste_iPhoneAppDelegate simbolo1]: unrecognized selector sent to instance 0x6b7c2d0
2011-09-30 09:17:21.715 Teste iPhone[28432:fb03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Teste_iPhoneAppDelegate simbolo1]: unrecognized selector sent to instance 0x6b7c2d0'
*** First throw call stack:
(0x166d062 0x17fed0a 0x166ecf开发者_运维技巧d 0x15d3f10 0x15d3cf2 0x166eed9 0x16eb2 0x16e4a 0xbc3e6 0xbc8af 0xbbb6e 0x3c2a0 0x3c4c6 0x22c74 0x16399 0x1557fa9 0x16411d5 0x15a6042 0x15a492a 0x15a3dd4 0x15a3ceb 0x1556879 0x155693e 0x1438b 0x272d 0x26a5)
terminate called throwing an exception(gdb) 


There is not enough information to help you. You need to look in the debugger console and show us the error and the stack.

However, I'm going to take a wild guess and say that you didn't connect the campo1 IBOutlet to its UIView in Interface Builder, and that it's nil. To fix, edit the view in Interface Builder (or in Xcode 4, just click on it), and drag the little circle next to the campo1 outlet (in the Connections tab) onto the UIView component that you want it to correspond to.

If that's not it, the error isn't here, but is probably caused by something else in your program.

[EDIT after seeing console]: Your connections look misconfigured. Why would it try to send the simbolo1 selector to Teste_iPhoneAppDelegate? It should send it to your ViewController. Did you play around with the connections (specifically, the delegate one) in Interface Builder -- or the class?


to set text in UITextField use

[campo1 setText:@"Only numeric values"];

and also don't forget to link IBOutlet UITextField* campo1; to proper UITextField in XCode IB

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜