即时创建一个RPN计算器。当按下磁带按钮继续播放第二个VC时,我需要代码的帮助才能查看我所有的计算结果。当按下磁带按钮时,它将显示输入的计算结果。第二个视图控制器中的功能。我知道编程。我在第一个VC中实施了prepareforsegue
。我不知道如何堆栈传递给numberOfRowsInSection
Segue:显示堆栈到第二个视图控制器
计算器引擎
class CalculatorEngine :NSObject
{
var operandStack = Array<Double>()
func updatestackWithValue(value: Double)
{
self.operandStack.append(value)
}
func operate(operation: String) ->Double
{
switch operation
{
case "×":
if operandStack.count >= 2
{
return self.operandStack.removeLast() * self.operandStack.removeLast()
第二个视图
class SecondVCViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
var array = [""]
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return array.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell") as UITableViewCell
cell.textLabel?.text = array[indexPath.row]
return cell
您的'CalculatorEngine'实例在哪里? –
我还没有添加它 –