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

abcdefg12345

macrumors 6502
Original poster
Jul 10, 2013
281
86
im trying to make a backspace button for an xcode project but its not working

heres the code for it can anyone edit it to make it work
 

Attachments

  • calc.zip
    89.9 KB · Views: 326

alexbussman

macrumors newbie
Aug 2, 2013
4
0
Sweden
A quick and dirty fix to your code would look something like this:
Code:
-(IBAction)Back:(id)sender {
    NSString *backspace = [conv_display stringValue];   
    float lengthofstring = backspace.length;
    if (lengthofstring == 0)
        return;

    backspace = [backspace substringToIndex:lengthofstring - 1];
    [conv_display setStringValue:backspace];
}

Reason is that you were thinking you got a NSString in the first line, but you were actually getting a NSTextField.

You would have found this easily if you used the actual class names instead of id for your IBOutlets.
It's always a good idea to avoid id unless you really have a good reason to use it.
Hope this helps you to continue :)

// Alex
 

abcdefg12345

macrumors 6502
Original poster
Jul 10, 2013
281
86
A quick and dirty fix to your code would look something like this:
Code:
-(IBAction)Back:(id)sender {
    NSString *backspace = [conv_display stringValue];   
    float lengthofstring = backspace.length;
    if (lengthofstring == 0)
        return;

    backspace = [backspace substringToIndex:lengthofstring - 1];
    [conv_display setStringValue:backspace];
}

Reason is that you were thinking you got a NSString in the first line, but you were actually getting a NSTextField.

You would have found this easily if you used the actual class names instead of id for your IBOutlets.
It's always a good idea to avoid id unless you really have a good reason to use it.
Hope this helps you to continue :)

// Alex

thanks a lot I tried it and it worked
 

Henley

macrumors newbie
Jul 2, 2012
2
0
A quick and dirty fix to your code would look something like this:
Code:
-(IBAction)Back:(id)sender {
    NSString *backspace = [conv_display stringValue];   
    float lengthofstring = backspace.length;
    if (lengthofstring == 0)
        return;

    backspace = [backspace substringToIndex:lengthofstring - 1];
    [conv_display setStringValue:backspace];
}

Reason is that you were thinking you got a NSString in the first line, but you were actually getting a NSTextField.

You would have found this easily if you used the actual class names instead of id for your IBOutlets.
It's always a good idea to avoid id unless you really have a good reason to use it.
Hope this helps you to continue :)

// Alex


Hey where would you implement this is in the main file or the header file?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.