本文介绍了iOS Swift ImageView无法在TableViewCell中隐藏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I recently added some swift code inside an objective-C project and I am facing something strange I cannot sort out.

我正在使用我自定义的搜索栏(来自Ray教程).在cellForRowAtIndexPath方法中,我可以自定义单元格标签,并且一切正常.唯一的事情是我无法根据if(BOOL)条件隐藏某些imageViews.快速代码肯定出了点问题,因为我可以使用相同的条件(BOOL)将那些图像隐藏在Objective-C文件中.

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.

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

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.

这篇关于iOS Swift ImageView无法在TableViewCell中隐藏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 15:42