This line is to get the reused cell. If it can be retrieved, the cell has memory and can be reused directly. If it cannot be retrieved, you have to create it yourself, which is the code you posted. In addition, you can also use the registration method:
If you don’t judge, a new one will be created every time, because you have one here
alloc
.Usually there is another line before this code:
This line is to get the reused cell. If it can be retrieved, the cell has memory and can be reused directly. If it cannot be retrieved, you have to create it yourself, which is the code you posted.
In addition, you can also use the registration method:
If you register, you don’t need to judge. Generally speaking, it is used like this:
Then, the
tableView:cellForRowAtIndexPath:
method does not require additional judgment, and can be taken directly: