iOS swift imageView无法在TableViewCell中隐藏

标签 ios uitableview swift uiimageview hidden

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

我正在使用我自定义的搜索栏(来自 Ray 教程)。在 cellForRowAtIndexPath 方法中,我可以自定义我的单元格标签,一切正常。唯一的问题是我无法根据 if (BOOL) 条件隐藏某些 imageView。我的 swift 代码一定有问题,因为我可以使用相同的 if (BOOL) 条件将这些图像隐藏在 Objective-C 文件中。

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

在 SearchVC 中(快速)

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
}

有没有人有想法?

最佳答案

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

关于iOS swift imageView无法在TableViewCell中隐藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27281831/

相关文章:

ios - 关闭 viewController 后重新加载 tableView

ios - 当我下拉刷新我的 UIScrollView 时,它需要我下拉到屏幕中间

ios - Facebook 的 API 和 App Store 的用户生成内容政策

iphone - 为什么我的 AudioQueueOutputCallback 不会被调用?

objective-c - 使用自定义名称初始化组件

ios - 如何在不禁用突出显示的情况下禁用uitable中的触摸行

swift - 使用通知中心将值设置为 TableView 中的标签

ios - 如何以编程方式使 TableViewCell 在灰色背景下显示为一张纸或 'label'?

json - Vapor 3 内容到 JSON 到字符串

ios - 从 Swift 中的 iOS 应用程序,如何打开 facebook 应用程序到个人资料页面的特定部分