When I set the Style of this TableViewCell to something other than Custom, I couldn't figure out how to access the parts inside the Cell and got stuck. This time I will write the explanation. It's easy once you know it.
If you select TableViewCell, there is a Style in the red frame, so you can change it from there.
Since cell is generated, we will write it in cellForRowAt
.
Define a constant cell and use tableView.dequeueReusableCell (withIdentifier :, for :)
to reuse the cell.
You will specify the Identifier and reuse the cell associated with it.
Then you will be able to access that cell,
Specify the part like cell.textLabel? .Text =" abc "
and write the process.
In the case of this Style, the part name on the left is textLabel and the part name on the right is detailLabel.
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell1", for: indexPath)
cell.textLabel?.text = "abc"
cell.detailTextLabel?.text = "def"
return cell
}
I set the numberOfRowsInSection to 4, so
As for the execution result, 4 Identidier cells specified by dequeueReusableCell are generated.
Recommended Posts