gpt4 book ai didi

iphone - CS193P - 添加取消按钮到 iOS 计算器

转载 作者:行者123 更新时间:2023-12-03 20:25:34 24 4
gpt4 key购买 nike

我最近开始在 iTunes U 上学习斯坦福大学关于 iPhone 开发的在线类(class)。

我现在正在尝试做前几堂课的家庭作业。我按照演练构建了一个基本计算器,但现在我正在尝试第一个作业,但我似乎无法解决它。其内容如下:

添加一个“C”按钮,用于清除所有内容(例如, View 中的显示、模型中的操作数堆栈、 Controller 中维护的任何状态等)。确保 3 7 C 5 结果在显示屏上显示 5。您必须将 API 添加到您的模型中才能支持此功能。

我需要添加什么API?

我尝试过这样的事情:

- (IBAction)CancelPressed {
self.Display.text = 0;
}

我知道这是错误的。我需要一些指导。提前致谢..如果问题很愚蠢,抱歉..

最佳答案

这是我的做法:

CalculatorViewController.m 中的代码:

//********************************************************
//
//This method is called when the user presses the Clear
//button (labeled "C").
//
//********************************************************

- (IBAction)clearPressed {
self.historyDisplay.text = @""; //Clear history label
self.display.text = @"0"; //Reset calculator display label to 0
_userIsInTheMiddleOfTypingANumber = NO; //Reset the user tracking feature
[self.brain clearStack]; //Calls method to "clear" the stack

//The following line may not be needed depended on your implementation of the
//decimal button. You may need something for your decimal implementation.
_userAlreadyEnteredDecimal = NO; //Reset the decimal boolean
}

然后在 CalculatorBrain.m 中:

//********************************************************
//
//"Clear" all values off of the stack.
//
//********************************************************
- (void)clearStack
{
_operandStack = nil; //Deallocate instance of the stack
}

关于iphone - CS193P - 添加取消按钮到 iOS 计算器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9048117/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com