gpt4 book ai didi

swift - NSIndexPath 中的 indexPath 是什么

转载 作者:行者123 更新时间:2023-11-28 13:00:54 25 4
gpt4 key购买 nike

我有这段代码

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

let cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "Cell")

cell.textLabel?.text = toDoList[indexPath.row] //will give us the 0th, 1st, 2nd etc..

return cell

谁能给我解释一下第一行的“indexPath”是什么?

最佳答案

indexPath 是参数的本地名称,其外部名称是cellForRowAtIndexPath

indexPath 是在函数体内定义的(您确实会使用它),而函数调用者在命名函数参数时必须使用 cellForRowAtIndexPath: let cell = tableView.delegate.tableView(tableView, cellForRowAtIndexPath: ...)

比较:

func sum1(a: Int, b: Int) -> Int {
return a + b
}

func sum2(a: Int, _ b: Int) -> Int {
return a + b
}

func sum3(integer a: Int, secondInteger b:Int) -> Int {
return a + b
}

sum1(1, b: 2)
sum2(1, 2)
sum3(integer: 1, secondInteger: 2)

是时候查看有关函数参数名称的 Apple 文档了:https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Functions.html

关于swift - NSIndexPath 中的 indexPath 是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33897079/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com