[英]HGPlaceholders Button Actions Swift Xcode
我仍在学习 Swift,因此不明白某些事情是如何工作的——比如占位符。 我将 HGPlaceholders 安装到我的项目中,以便与我从 Firebase 下载信息的 TableViews 一起使用。 我似乎无法弄清楚如何给各种屏幕(有多个屏幕,每个屏幕都有一个“再试一次”或“取消”按钮)按钮一个动作。
请熟悉 HGPlaceholders 的人帮助我吗? 如何给tableView.showLoadingPlaceholder()
之类的东西一个动作? 目前,默认情况下,它只是将某些内容打印到控制台。
是的,我阅读了它的文档。 是的,我搜索了互联网寻求帮助。 不,我找不到任何解决这个问题的方法。
谢谢!
HGPlaceholders: HGPlaceholders 文档
这就是 function 在点击占位符中的按钮时默认打印的内容,如下所示:
@IBAction func sendPlaceholderAction(_ sender: Any) {
onActionButtonTap?()
print("Placeholder action button tapped")
}
我想通了...带我永远因为我很愚蠢。
这些操作在您放置在 class 底部的 function 中处理,您的表视图位于:
extension TestViewController: PlaceholderDelegate {
func view(_ view: Any, actionButtonTappedFor placeholder: Placeholder) {
print(placeholder.key.value)
if placeholder.key.value == "loading" {
print("The placeholder is the Loading screen and Cancel button")
} else if placeholder.key.value == "noResults" {
print("The placeholder is the noResults screen and Try Again button")
} else if placeholder.key.value == "noConnection" {
print("The placeholder is the noConnection screen and Try Again button")
} else if placeholder.key.value == "error" {
print("The placeholder is the error screen and Try Again button")
}
}
}
这是为四个默认选项中的每一个提供操作的示例。
希望这可以帮助其他无法弄清楚的人哈哈!
旁注:另一件事,您还必须在 viewDidLoad 中设置 tableView 的 placeholderDelegate。
tableView.placeholderDelegate = self
如果不这样做,function 将永远不会执行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.