即時創建一個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'實例在哪裏? –
我還沒有添加它 –