Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iPhone在执行命令行之前让时间流逝_Iphone_Objective C - Fatal编程技术网

iPhone在执行命令行之前让时间流逝

iPhone在执行命令行之前让时间流逝,iphone,objective-c,Iphone,Objective C,我正在为iPhone构建一个基本的计算器应用程序。我已经掌握了所有的基本知识,但我现在只是在调整它。目前,如果我先按一个数字,然后按一个操作,再按另一个数字并点击=,则显示结果。我想要的是,当我按下一个数字,然后是一个操作时,我希望操作显示在屏幕上。这就是我所拥有的: NSString *operation=[[sender titleLabel] text]; [display setText:operation]; double result=[[self brain

我正在为iPhone构建一个基本的计算器应用程序。我已经掌握了所有的基本知识,但我现在只是在调整它。目前,如果我先按一个数字,然后按一个操作,再按另一个数字并点击=,则显示结果。我想要的是,当我按下一个数字,然后是一个操作时,我希望操作显示在屏幕上。这就是我所拥有的:

    NSString *operation=[[sender titleLabel] text];
    [display setText:operation];
    double result=[[self brain] performOperation:operation];
    [display setText:[NSString stringWithFormat:@"%g",result]];

所以这个代码只显示最后一行,而不是操作。但是,如果我注释掉最后一行,则会显示该操作。所以我在想,如果我能在调用第二个setText之前让一段时间过去,这将解决我的问题,除非有其他方法?

当然,您正在用第二个
setText:
调用重写display。 为什么不使用:

[display setText:[NSString stringWithFormat:@"%@%g", operation, result]]

您可以使用performSelector:withObject:afterDelay

[self performSelector:@selector(...) withObject:nil afterDelay:1];