2014-12-03 73 views
0

我最近在一个Objective-C项目中添加了一些swift代码,并且面临着一些我无法理清的奇怪东西。iOS swift imageView无法在TableViewCell中隐藏

我正在使用自定义的Searchbar(来自Ray教程)。在cellForRowAtIndexPath方法中,我可以自定义我的单元格标签,并且一切正常。唯一的问题是我不能根据if(BOOL)条件隐藏一些imageViews。我的swift代码一定是错误的,因为我可以使用相同的if(BOOL)条件将这些图像隐藏在Objective-C文件中。

以防万一我发布我的代码,如果有人可以帮助我。

在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 
} 

有没有人有一个想法?

回答

7
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 
} 

在行cell.imageMail.hidden == true你基本上是比较而不是分配。如果你想分配值,它应该简单地是cell.imageMail.hidden = true

+0

啊哈这么可怕的初学者的错误......对我来说太愚蠢了。非常感谢 :-) – Trichophyton 2014-12-03 22:23:47