问题
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