When I develop one iOS app, I encounted the problem – how to select the first cell in the tableview and without reusing it? The solution to the problem as following.

I want to select the first cell in the tableview and give it an alpha of one hundred percent, and only for the first cell and this style should not be reused by the dequeueReusableCell way. See the code I used as following.

if indexPath.row == 0 {
   cell.imageView.alpha = 1.0
}

I used the above code within the function cellForItemAt , it will be set alpha of 1.0 to every 7th cell. I only want it to be applied on the first cell and the style should not be reused…

However, how can I solve the problem? Does it right to create another custom cell or is there a kind method in code do achieve this?

After some google research, I found solutions to the question: how to select the first cell in a tableview without reusing it?

1.The first solution to how to select the first cell in a tableview without reusing it:

Just to reset the imageView’s alpha if it’s not the first cell as the below code.

if indexPath.row == 0 {
   cell.imageView.alpha = 1.0
}
else {
   cell.imageView.alpha = 0.0 // or whatever alpha value you need
}

2.The second solution to choose the first cell in a tableview and without reusing it:

Create a UITableViewCell xib subclass. Then you can register the same cell with different reuseIdentifiers when you’re setting up your table.

tableView.register(CustomCell, forCellReuseIdentifier: "AlphaCell")
tableView.register(CustomCell, forCellReuseIdentifier: "{REUSE_ID}")

When you setup your cell in:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

dequeue “AlphaCell” for your first cell, and “{REUSE_ID}” for your other cells.

Although, to this problem case it is a lot of overkill, but it works. If you encounted the same problem, you can try it or to find more effective method, then welcome you to share your better solutions.