I am continuing an app for iOS directed to iPad. And asked a question this morning on the site where I got the right answer to my question. But for some reason, the Alpha is not working in cells of my table.
This is my View ties TableView:

And this is my Swift code:
import UIKit
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
    let data:[String] = ["Row 0","Row 1", "Row 2","Row 3","Row 4","Row 5","Row 6"]
    @IBOutlet var tableView: UITableView!
    var rowSelected:Int! = nil
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return data.count
    }
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell:Cell = self.tableView.dequeueReusableCellWithIdentifier("cell") as! Cell
        if rowSelected != nil {
            if rowSelected > indexPath.row {
                cell.alpha = 0.7
            } else if rowSelected == indexPath.row {
                cell.alpha = 1.0
            } else {
                cell.alpha = 0.3
            }
        }
        cell.labelText.text = self.data[indexPath.row]
        return cell
    }
    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        self.rowSelected = indexPath.row
        tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic)
    }
}
When I select one row, nothing happens, the Alpha does not. In this example, I applied the Alpha directly in cell (I disabled the Opaque option in the cell - the cell is not opaque). In the original app I have 2 Labels, 2 buttons and a picture. To be more practical, necessary for the Alpha is used directly in the Cell.
Can someone help me?
I know this is an old thread. But I just want to leave my suggestion here if anyone may find it useful. You can apply the alpha to the UITableViewCell's content view this works for me.
cell.contentView.alpha = 0.3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With