在UILabel中删除按键无效

计算器应用的界面是UILabel,现在删除键出问题:

.h

IBOutlet UILabel *display;

.m

- (IBAction)Del 
{
    [display.text substringToIndex:display.text.length -1];
}

在模拟器的时候正常运行,但是到真机上不行。不知道问题出在哪里。

display.text= [display.text substringToIndex:display.text.length -1];

这样就好了。你开始的时候只是截取了一个新的字符串,没有给display.text新的值。还有,你这样写的话,在display.text.lenght=0的时候,会报错,你可以加一个判断语句

if(display.text.lenght>0){display.text= [display.text substringToIndex:display.text.length -1];}

这样的话就完全可以了。