ios - 在 iOS 计算器上创建退格键

标签 ios objective-c iphone string calculator

我正在尝试添加一个退格按钮以删除计算器中最后输入的数字,但我似乎无法实现。这是我尝试过的:

-(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 - 在 iOS 计算器上创建退格键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6591551/

相关文章:

ios - 在 iOS 扩展和应用程序之间使用 UIApplication.shared 共享 CocoaPod

objective-c - 求计算器中根底的幂

iphone - 如何解决Instruments检测到的泄漏,其责任库是Apple的框架?

ios - 为什么我的 UIScreen 大小是 iPhone 本身大小的一半(以像素为单位)?

ios - ios App中全局模型的使用

iphone - ALAssetsLibrary 太慢 - Objective-C

iphone - NS_ENUM 给出编译器关于前向引用的警告

ios - Xcode 6.1 : iPhone 5s simulator returns blank screen

ios - wav 到 aac 转换 interruptListener 不在 ios 中调用

ios - iOS-选择模型类别