CS193P-向iOS计算器添加取消按钮 [英] CS193P - Adding cancel button to iOS calculator
问题描述
我最近开始在iTunes U上学习斯坦福大学关于iPhone开发的在线课程.
I recently started following the online course on iPhone development from Stanford University on iTunes U.
我现在正在做前几节课的作业.我完成了构建基本计算器的演练,但是现在我正在尝试第一个任务,但似乎无法解决.如下:
I'm trying to do the homework assignments now for the first couple of lectures. I followed through the walkthrough where I built a basic calculator, but now I'm trying the first assignment and I can't seem to work it out. It's a follows:
添加一个"C"按钮以清除所有内容(例如,视图中的显示,模型中的操作数堆栈,控制器中维护的任何状态,等等).确保3 7 C 5导致5出现在显示屏中.您必须将API添加到模型中才能支持此功能.
Add a "C" button that clears everything (for example, the display in your View, the operand stack in your Model, any state you maintain in your Controller, etc.). Make sure 3 7 C 5 results in 5 showing in the display. You will have to add API to your Model to support this feature.
我需要添加什么API?
What API do i need to add?
我尝试过这样的事情:
- (IBAction)CancelPressed {
self.Display.text = 0;
}
我知道这是错误的.我需要一些指导.在此先谢谢您..很抱歉这个问题很愚蠢..
I know this is wrong. I need some guidance. Thanks in advance..Sorry if the question is stupid..
推荐答案
我也在iTunesU上浏览2011年秋季版.这是我完成此操作的方式.
I am also going through the fall 2011 version on iTunesU. Here is the way I accomplished this.
- (IBAction)clearPressed {
self.display.text = @"0";
self.userIsInTheMiddleOfEnteringANumber = NO;
self.brain = nil;
}
唯一的事情是我实际上不必在模型中添加API.因为控制器有一个CalculatorBrain实例变量,所以我只是把它扔掉了,并且由于我们懒惰地实例化了我们的大脑吸气剂,所以下次我调用吸气剂时,我将得到一个全新的(已经清除).
The only thing is I actually did not have to add API to my model. Because the controller has a CalculatorBrain instance variable I just toss that out, and since we lazily instantiated our brain getter, I'll get a brand new one (already cleared) next time I call the getter.
这篇关于CS193P-向iOS计算器添加取消按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!