Reputation: 4363
I would like to select the first cell in the tableview and give it an alpha of 100%, only for the first cell and this style should not be reused by the dequeueReusableCell
method.
if indexPath.row == 0 {
cell.imageView.alpha = 1.0
}
When I use 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... How can I solve this? Should I create another custom cell or is there a kind approach in code do achieve this?
Upvotes: 0
Views: 135
Reputation: 237
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.
Upvotes: 2
Reputation: 763
You should reset the imageView's alpha if it's not the first cell.
if indexPath.row == 0 {
cell.imageView.alpha = 1.0
}
else {
cell.imageView.alpha = 0.0 // or whatever alpha value you need
}
Upvotes: 2