About UITableViewCell

Asked 2 years ago, Updated 2 years ago, 68 views

Please.

I am currently implementing UITableViewCell, but how do I configure two labels in one cell?

With just one Cell,

override functableView(_tableView:UITableView, cellForRowAtindexPath:IndexPath)->UITableViewCell{
    let_cell=tableView.dueReusableCell(withIdentifier:cellIdentifier, for:indexPath) as UITableViewCell
    letcell=_cell
    cell.textLabel?.text="a"
    return cell
}

I can do it with , but how can I implement it if I want to display another character in the same cell?

***Additional ***
Create a cell instance,
<variable name>:label=cell.viewWithTag(x)as?UILabel
In , I set up a tag for each object and specified it in viewWithTag().

Could you ask me one additional question?
I often hear MagicNumber, but I don't think this kind of coating is a problem for individuals, but will it be effective for development involving people other than myself?Or is there an efficient method that is easier to understand?This may be an abstract question, but I appreciate your cooperation.

swift3

2022-09-30 17:27

1 Answers

I often hear MagicNumber, but I don't think this kind of coating is a problem for individuals, but will this kind of method be effective for development involving people other than myself?

The problem with magic numbers is that you can't read only the code such as "why" and so on, so

Enable variable names to convey intentions
1.08*price=>(1+tax)*price

Write the reason for this in the comments

It can be avoided in such a way as

I will add additional information below the question.

I think it will be easier to get answers including the title if you ask again


2022-09-30 17:27

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.