2014-12-03 75 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