2017-03-28 31 views
0

我試圖捕捉按下一個按鈕的事件,我可以把它傳遞給一個表視圖,其定時在那裏我可以捕獲的時間和它傳遞給tableview,但我似乎無法捕捉事件類型。IOS - 按鈕捕獲事件按下,並傳遞給泰伯維

在下面的例子中我可以捕捉一個目標是打進的時間,但我需要的話進球也傳遞給tableview中

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 

     let cell = UITableViewCell(style: UITableViewCellStyle.value1, reuseIdentifier: "cell") 

     cell.backgroundColor = self.view.backgroundColor 

     **cell.textLabel?.text = "Help here to capture the button event"** 
     cell.detailTextLabel?.text = time[indexPath.row] 

     return cell 
    } 


    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 

     return time.count 
    } 

@IBAction func goalClicked(_ sender: UIButton) { 

    let stopWatchString = stopWatch.elapsedTimeSinceStart() 
    stopwatchLabel.text = stopWatchString 

    time.insert(stopWatchString, at: 0) 
    self.tableView.reloadData()   
} 

感謝

回答

-1

排序它。

var event: String! 
在的tableView

cell.textLabel?.Text = event 

最後在按鈕功能

然後

event = "Goal" 
tableView.reloadData()