2017-02-23 54 views
0

我有一個tableview有事件,用戶可以選擇是,不,也許選項從alert controller。我喜歡計算是,不,也許是。我可以用UISwitch和計算的話,如果是像這樣沒有選項,並在eventStatus有沒有辦法在表格視圖中計算警報?

eventSwitch.isOn = object.value(forKey: "eventStatus") as! Bool 

存儲的價值有沒有一種方法,我可以做報警控制器,它具有是一樣的,沒有,也許(3個選項)?

+1

如何實現在警報操作的計算? – user3581248

+0

是的,這是我無法弄清楚,我到處搜索它 – Coder221

回答

1

如何實現這些計算在警報動作處理程序:

var yesCount = 0 
var noCount = 0 
var maybeCount = 0 
func showAlert() { 
    let alert = UIAlertController(title: "title", message: "msg", preferredStyle: .alert) 
    alert.addAction(UIAlertAction(title: "yes", style: .default) { _ in 
     self.yesCount += 1 
    }) 
    alert.addAction(UIAlertAction(title: "no", style: .default) { _ in 
     self.noCount += 1 
    }) 
    alert.addAction(UIAlertAction(title: "maybe", style: .default) { _ in 
     self.maybeCount += 1 
    }) 
    present(alert, animated: true, completion: nil) 
} 
+0

欣賞它,現在得到了主意。 – Coder221

相關問題