【问题标题】:Swift Eureka: Can't dynamically hide/show ButtonRow inside cellUpdateSwift Eureka:无法在 cellUpdate 中动态隐藏/显示 ButtonRow
【发布时间】:2017-08-22 00:17:17
【问题描述】:

这是我显示和隐藏行的代码。我基本上设置了Eureka FAQ中提到的隐藏属性。请让我知道这是否是设置隐藏属性以显示/隐藏行的正确方法。

    form
    +++ Section("main")
    <<< ButtonRow () { (row: ButtonRow) -> Void in
        row.tag = "sampleRow"
        if self.shouldHide {
            print("hide exampleRow")
            row.hidden = true
        } else {
            print("show exampleRow")
            row.hidden = false
        }
    }
    .cellSetup ({ [unowned self] (cell, row) in
        row.title = "Title Example"
        row.cell.tintColor = .red
    })
    .cellUpdate({ [unowned self] (cell, row) in
        if self.shouldHide {
            print("cellUpdate: hide exampleRow \(self.shouldHide)")
            row.hidden = true
        } else {
            print("cellUpdate: show exampleRow \(self.shouldHide)")
            row.hidden = false
        }
    })
    .onCellSelection({ (cell, row) in
        print("It's Me!")
    })

稍后在代码中,我将变量 shouldHide 更新为 true 或 false 并调用 tableView.reloadData(),它确实调用了 cellUpdate 块但没有任何反应。有人可以帮忙吗?这是我的项目,您可以克隆并重现此问题。 https://github.com/cuongta/testEurekaHideShow

再次感谢!

【问题讨论】:

  • 您何时需要隐藏和显示?还有一个问题是你在哪里更新尤里卡表单?
  • 我需要在单击已连接到 IBAction 的按钮时隐藏和显示。这是完整的源代码:github.com/cuongta/testEurekaHideShow/blob/master/…
  • 我的回答对你有帮助吗?
  • 不,没有用。只有在选择单元格时,才会在oncellselection。 span>
  • 检查我的更新答案

标签: ios swift swift3 eureka-forms


【解决方案1】:

EurekaForm 中隐藏一行甚至一个部分的正确方法是修改.hidden 属性并在此之后调用.evaluateHidden() 方法,因此为了使您的代码工作您需要进行此修改,您的shouldHide此任务不需要 var

用这个替换.onCellSelection回调方法

.onCellSelection({ (cell, row) in
                    print("It's Me!")
                    row.hidden = true
                    row.evaluateHidden()
                })

完整代码

    form +++ Section("main")
        <<< ButtonRow () { (row: ButtonRow) -> Void in
            row.tag = "sampleRow"
            }
            .cellSetup ({ (cell, row) in
                row.title = "Title Example"
                row.cell.tintColor = .red
            })
            .onCellSelection({ (cell, row) in
                print("It's Me!")
                row.hidden = true
                row.evaluateHidden()
            })

更新

如果您想从任何其他上下文中隐藏一个单元格,您需要通过标签获取该单元格,然后您可以修改 .hidden 并调用 .evaluateHidden() 方法将完成

@IBAction func btnAction(_ sender: Any) {
    if let buttonRow = self.form.rowBy(tag: "sampleRow") as? ButtonRow
    {
        buttonRow.hidden = true
        buttonRow.evaluateHidden()
    }
}

【讨论】:

    猜你喜欢
    • 2011-03-26
    • 1970-01-01
    • 1970-01-01
    • 2012-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-01
    相关资源
    最近更新 更多