【发布时间】:2012-11-14 06:32:39
【问题描述】:
我正在制作一个 iOS 计算器,但我在使用退格按钮时遇到了一些小问题(用于删除标签上显示的值的最后一个数字)。
要获取我使用的标签上的当前值
double currentValue = [screenLabel.text doubleValue]
在其他问题之后,我尝试了类似
-(IBAction)backspacePressed:(id)sender
{
NSMutableString *string = (NSMutableString*)[screenLabel.text];
int length = [string length];
NSString *temp = [string substringToIndex:length-1]
;
[screenLabel.text setText:[NSString stringWithFormat:@"%@",temp]];
}
但它不起作用,
(Xcode 说“setText is deprecated”,“NSString may not respond to setText”并且第一个需要一个标识符 IBAction 内的代码行)
而且我并不真正理解这段代码以使其自己工作。
我该怎么办?
【问题讨论】:
标签: objective-c ios xcode calculator