【问题标题】:iOS swift imageView cannot be hidden in TableViewCelliOS swift imageView不能隐藏在TableViewCell中
【发布时间】:2014-12-03 21:18:34
【问题描述】:

我最近在一个 Objective-C 项目中添加了一些 swift 代码,但我遇到了一些我无法解决的奇怪问题。

我正在使用我自定义的搜索栏(来自 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
}

有人有想法吗?

【问题讨论】:

    标签: ios uitableview swift uiimageview hidden


    【解决方案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
    }
    

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

    【讨论】:

    • 啊哈,初学者的错误真是太糟糕了……我太愚蠢了。非常感谢:-)
    猜你喜欢
    • 2016-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多