Я следую онлайн-курсу, чтобы изучить iOS. Я использую Swift 4.2.
Мой вопрос об этом методе:
// This function is defining each cell and adding contenet to it.
internal func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: .default, reuseIdentifier: "Cell")
cell.textLabel?.text = cellContent[indexPath.row]
return cell
}
Как именно вышеуказанный метод работает в следующем коде? Я знаю, что описанный выше метод описывает каждую ячейку табличного представления, но вызывается ли он табличным представлением для каждой строки?
Что именно означает indexpath.row? Я запутался с этим.
Пожалуйста, помогите мне. Спасибо.
import UIKit
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
var cellContent:Array<String> = ["Amir", "Akbar", "Anthony"]
// This function is setting the total number of cells in the table view
internal func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return cellContent.count
}
// This function is defining each cell and adding contenet to it.
internal func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: .default, reuseIdentifier: "Cell")
cell.textLabel?.text = cellContent[indexPath.row]
return cell
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
}