【问题标题】:Cannot find a initializer for type "UITableViewRowAction"找不到类型“UITableViewRowAction”的初始化程序
【发布时间】:2015-09-08 17:27:32
【问题描述】:
为什么即使我输入了正确的UITableViewRowAction 声明,它仍然向我显示此消息?
var shareAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "Share",
handler: { (action:UITableViewRowAction!, indexPath: NSIndexPath) -> Void in
【问题讨论】:
标签:
ios
swift
uitableviewrowaction
【解决方案1】:
Xcode 6.4 文档说这两个参数都应该是隐式展开的可选项。
var shareAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "Share",
handler: { (action: UITableViewRowAction!, indexPath: NSIndexPath!) -> Void in
或者在 Xcode 7 中,这两个参数都不是可选的。
var shareAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "Share",
handler: { (action: UITableViewRowAction, indexPath: NSIndexPath) -> Void in
无论哪种方式,你都应该尝试
var shareAction = UITableViewRowAction(style: .Default, title: "Share") {
action, indexPath in
/* ... */
}
哪种方式更快捷。