我创建了一个UIAlertView实例,并将其命名为alert,我做了标题和消息,现在我在addButtonWithTitle上。我已经尝试过执行“唤醒它的时间(strDate)”,并且还尝试过“需要唤醒的时间” + strDate。这是UIAlertView实例的代码:
let alert = UIAlertView()
alert.title = "WAKE UP"
alert.message = "Time to wake up it's"
alert.addButtonWithTitle("I'm Up!")
alert.show()
在第三行上应该说alert.message =“是时候唤醒它的strDate了”
strDate应该是一个变量
这是我的strDate
var strDate = timeFormatter.stringFromDate(theDatePicker.date)
其他答案是正确的,但是您应该使用以下代码:
let alert = UIAlertController(title: "WAKE UP", message:nil, preferredStyle: UIAlertControllerStyle.Alert);
var strDate = "Ok";
alert.message = "Time to wake up " + strDate;
let dismissHandler = {
(action: UIAlertAction!) in
self.dismissViewControllerAnimated(true, completion: { () -> Void in
})
}
alert.addAction(UIAlertAction(title: "I'm Up!", style: .Default, handler: dismissHandler))
presentViewController(alert, animated: true) { () -> Void in
}
根据Swift文档,您应该使用+
运算符在字符串中添加内容。
String连接还支持加法运算符:
“ hello,” +“ world” //等于“ hello,world”
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句