开发者

Creating backspace on iOS calculator

I'm trying to add a backspace button to remove the last entered digi开发者_如何学编程t in a calculator, but I can't seem to get it. Here is what I've tried:

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

    NSMutableString *string = (NSMutableString*)[display text];

    int length = [string length];

    NSString *temp = [string substringFromIndex:length-1];

    [display setText:[NSString stringWithFormat:@"%@",temp]];

}

Any ideas?


I think you want [string substringToIndex:length-1] instead of [string substringFromIndex:length-1].


Use subStringToIndex method instead of subStringFromIndex

NSString *temp = [string substringToIndex:length-1];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜