gpt4 book ai didi

ios - 删除按钮计算器 *帮助*

转载 作者:行者123 更新时间:2023-11-29 02:41:32 25 4
gpt4 key购买 nike

我的计算器有这段代码,可以让我一次删除一个数字!

- (IBAction)deleteButton:(id)sender {
NSString *string = [Screen text];
int length = [string length];
NSString *temp = [string substringToIndex:length-1];

if ([temp length] == 0) {
temp = @"0";
}
[Screen setText:temp];
}

它有效,但每当我输入另一个数字时,它会重置为整个数字,所以让我们以此为例。

我的号码是5678,(我删除了678),所以我的新号码是5,(现在如果我按另一个号码),它会回到56781(1是新号码)

这是我的项目的完整代码! ---> http://txt.do/oduh

最佳答案

如您的代码所示,您使用 SelectNumber 在任何地方存储值,但在 deleteButton 方法中,您没有在 SelectNumber 中存储新值>。因此,您需要在 deleteButton 中设置新值。

- (IBAction)deleteButton:(id)sender {
NSString *string = [Screen text];
int length = [string length];
NSString *temp = [string substringToIndex:length-1];

if ([temp length] == 0) {
temp = @"0";
}
SelectNumber = [temp intValue]; // set new value here
[Screen setText:temp];
}

关于ios - 删除按钮计算器 *帮助*,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25717096/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com