Swift Eureka: 不能在 cellUpdate 中动态 hide/show ButtonRow
Swift Eureka: Can't dynamically hide/show ButtonRow inside cellUpdate
这是我显示和隐藏该行的代码。我基本上设置了尤里卡常见问题解答中提到的隐藏属性。请告诉我这是否是将隐藏属性设置为 show/hide 行的正确方法。
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
再次感谢!
在 EurekaForm
中隐藏行甚至部分的正确方法是修改 .hidden
属性 并在之后调用 .evaluateHidden()
方法,以便让您您需要进行此修改的代码工作,此任务不需要您的 shouldHide
变量
用这个替换.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()
}
}
这是我显示和隐藏该行的代码。我基本上设置了尤里卡常见问题解答中提到的隐藏属性。请告诉我这是否是将隐藏属性设置为 show/hide 行的正确方法。
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
再次感谢!
在 EurekaForm
中隐藏行甚至部分的正确方法是修改 .hidden
属性 并在之后调用 .evaluateHidden()
方法,以便让您您需要进行此修改的代码工作,此任务不需要您的 shouldHide
变量
用这个替换.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()
}
}