在以下功能中:
func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {
return 10
}
是通过以numberOfRowsInSection
为参数调用函数section
返回的结果的第二个参数?如果是这样,它从哪里获得section
?
答案 0 :(得分:1)
此语法允许为参数设置一个名称,该名称与用于捕获该参数值的局部变量的名称不同。
numberOfRowsInSection
是调用此函数时使用的参数的名称。section
是保存传递值的局部变量的名称。所以你会像这样调用这个函数:
Int rowCount = tableView(tableView: aTabelView, numberOfRowsInSection: 10);
在该函数中,您将使用如下参数:
func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {
return section;
}
答案 1 :(得分:0)
numberOfRowsInSection
是调用函数时的参数名称。 section
是函数中的参数名称。因此,例如,您可以按如下方式调用此函数:
myObject.tableView(aView, numberOfRowsInSection:4)
但是从函数中,您将引用4
,如下所示:
let valueOfSectionArgument = section