在UITableViewCell定义中,闭包是如何工作的?
从联机教程中检索到以下代码段:在UITableViewCell定义中,闭包是如何工作的?,uitableview,closures,swift2.1,Uitableview,Closures,Swift2.1,从联机教程中检索到以下代码段: typealias TableCellConfigurationBlock = (cell: ScheduleTableViewCell, indexPath: NSIndexPath, session: Session) -> () “typealias”似乎是一个闭包;还是生成void()的元组? 但我不知道它在以下功能中是如何工作的: func tableView(tableView: UITableView, cellForRowAtIn
typealias TableCellConfigurationBlock = (cell: ScheduleTableViewCell, indexPath: NSIndexPath, session: Session) -> ()
“typealias”似乎是一个闭包;还是生成void()的元组?
但我不知道它在以下功能中是如何工作的:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("ScheduleTableViewCell") as! ScheduleTableViewCell
let session = sessionForIndexPath(indexPath)
if let configureBlock = tableCellConfigurationBlock {
configureBlock(cell: cell, indexPath: indexPath, session: session)
}
return cell
}
解释?
参考资料?放得很好。简明的我在“我的游乐场”玩它。
typealias ClosureType = (i: Int, s: String, d: Double)->String
let c1: ClosureType = {
// has three input parameters
// i:Int, s: String, d: Double
// and returns String
i, s, d in
return s + " integer: \(i) and double: \(d)"
}
let c2: ClosureType = {
$1 + " integer: \($0) and double: \($2)"
}
print(c1(i: 1,s: "You pass in",d: 3.14))
print(c2(i: 1,s: "You pass in",d: 3.14))
/*
You pass in integer: 1 and double: 3.14
You pass in integer: 1 and double: 3.14
*/