Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个 iPad 应用程序,我在其中添加了一个 calc 类型的键盘,带有 9 个数字和一个后退按钮。使用所有数字,我正在像这样颠覆文本字段的值[number setText:[number.text stringByAppendingString:@"number"]];。现在在回溯操作中,我需要删除最后添加的价值。我试过这个[number.text substringToIndex:[number.text length]-2];但是没有运气。有人能帮我实现吗?
[number setText:[number.text stringByAppendingString:@"number"]];
[number.text substringToIndex:[number.text length]-2];
你对 substringToIndex 的结果做了什么?
你需要类似的东西,
[number setText:[number.text substringToIndex:[number.text length]-2]];
这是答案:
if ( [number.text length] > 0) number.text = [number.text substringToIndex:[number.text length] - 1];