在iOS计算器上创建退格键 [英] Creating backspace on iOS calculator
本文介绍了在iOS计算器上创建退格键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试添加一个退格按钮来删除计算器中最后输入的数字,但我似乎无法得到它。以下是我的尝试:
I'm trying to add a backspace button to remove the last entered digit 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]];
}
有什么想法吗?
推荐答案
我想你想要 [string substringToIndex:length-1]
而不是 [string substringFromIndex:length-1]
。
这篇关于在iOS计算器上创建退格键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文