0
我試圖創建一個AlertController
的alertAction
定製的標題,以根據不同的switches
狀態條件函數:提前爲alertAction定製標題IOS
let alert = UIAlertController(title: 「Got it」, message: 「Please, select:」, preferredStyle: UIAlertControllerStyle.Alert)
name01: String = "name01"
name02: String = "name02"
name03: String = "name03"
if switch01.on {
let action01 = UIAlertAction(title: name01, style: .Default) { (_) in }
}
if switch02.on {
let action02 = UIAlertAction(title: name02, style: .Default) { (_) in }
}
if switch03.on {
let action03 = UIAlertAction(title: name03, style: .Default) { (_) in }
}
let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel) { (_) in }
alert.addAction(action01)//Cannot convert value of type 'String' to expected argument type 'UIAlertAction'
alert.addAction(action02)//Cannot convert value of type 'String' to expected argument type 'UIAlertAction'
alert.addAction(action03)//Cannot convert value of type 'String' to expected argument type 'UIAlertAction'
alert.addAction(cancelAction)//No error
感謝。
'action0n'在'if swith0n.on {}'之外是無效的。他們不存在。 =>'如果swith0n.on {讓action0n = ... alert.addAction(action0n)}' – Larme