Ios UITableView-什么是indexPath?
我正在做一个在线教程,建立一个单元格表,我有一个问题。在下面的第二个函数表视图中。。。具体是什么 更重要的是,程序如何知道在每次调用函数时更新通过indexPath传递的值Ios UITableView-什么是indexPath?,ios,swift,uitableview,Ios,Swift,Uitableview,我正在做一个在线教程,建立一个单元格表,我有一个问题。在下面的第二个函数表视图中。。。具体是什么 更重要的是,程序如何知道在每次调用函数时更新通过indexPath传递的值 var rowNumber = 0 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return 50 } func tableView(_ tableView: UITableVie
var rowNumber = 0
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 50
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let rowCell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "Cell")
rowCell.textLabel?.text = String(indexPath.row + 1)
return rowCell
}
TableView分为多个部分。每个部分包含一定数量的行。IndexPath包含有关函数询问的节中的哪一行的信息。根据这些数字,您正在配置单元格以显示给定行的数据。应用程序在需要显示行时正在执行此函数。例如,向下滚动tableview,屏幕上将显示下一个单元格。例如,要使用正确的文本配置此单元格,它会询问您在该位置的行(节和行)上应该显示什么
此外,为了提高性能,您应该使用tableView.dequeueReusableCellWithIdentifier函数而不是cell的init来创建单元格。您是否阅读了
UITableView
的参考文档?它有一节介绍了什么是indepath
(nsindepath
)。另请参阅indepath
的文档。是的,我已经阅读了文档,否则我不会询问。谢谢你。