iOS swift imageView cannot be hidden in TableViewCell

半腔热情 提交于 2020-01-17 06:12:31

问题


I recently added some swift code inside an objective-C project and I am facing something strange I cannot sort out.

I am using the Searchbar (from Ray tutorial) that I customized. In the cellForRowAtIndexPath method, I can customize my cell labels and everything works fine. The only thing is that I cannot hide some imageViews according to if (BOOL) conditions. Something must be wrong with my swift code since I can hide those image in Objective-C files with the same if (BOOL) conditions.

Just in case I post my code if anyone can help me.

In SearchVC (swift)

class aCell : UITableViewCell {
    @IBOutlet weak var some label...
    @IBOutlet weak var imageFacturation: UIImageView!
    @IBOutlet weak var imageMail: UIImageView!
}

class PatientSearchViewController : ...

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let cell = self.tableView.dequeueReusableCellWithIdentifier("CellSwift") as aCell // aCell is a class defined inside the file where I attach the label and imageView properties
    var person : ClassObject

    if tableView == self.searchDisplayController!.searchResultsTableView {
        person = filteredObjects[indexPath.row]
    } else {
        person = objects[indexPath.row]
    }

    // Configure the cell
    cell.labelLastname.text = person.lastname
    cell.labelFirstname.text = person.firstname

    if person.hasMailSent == false {
        cell.imageMail.hidden == true // --> does not work in swift code but is Hidden in objective-C with the setHidden:true
    }
    if person.hasFacturation == false {
        cell.imageFacturation.hidden == true // --> does not work in swift code but is Hidden in objective-C with the setHidden:true
    }

    return cell
}

Does anyone have an idea?


回答1:


if person.hasMailSent == false {
    cell.imageMail.hidden == true // --> does not work in swift code but is Hidden in objective-C with the setHidden:true
}
if person.hasFacturation == false {
    cell.imageFacturation.hidden == true // --> does not work in swift code but is Hidden in objective-C with the setHidden:true
}

In the line cell.imageMail.hidden == true you are basically comparing and not assigning. It should simply be cell.imageMail.hidden = true if you want to assign the value.



来源:https://stackoverflow.com/questions/27281831/ios-swift-imageview-cannot-be-hidden-in-tableviewcell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!