【问题标题】:HGPlaceholders Button Actions Swift XcodeHGPlaceholders 按钮操作 Swift Xcode
【发布时间】:2021-01-14 22:33:58
【问题描述】:

我还在学习 Swift,因此不明白某些东西是如何工作的——比如占位符。我将 HGPlaceholders 安装到我的项目中,以便与我从 Firebase 下载信息的 TableViews 一起使用。我似乎无法弄清楚如何为各种屏幕(有多个屏幕,每个屏幕都有一个“重试!”或“取消”按钮)按钮提供一个操作。

请熟悉 HGPlaceholders 的人帮助我吗?我该如何提供类似的东西 tableView.showLoadingPlaceholder() 一种行为?目前它只是在控制台上打印一些东西,默认情况下。

是的,我阅读了它的文档。是的,我搜索了互联网寻求帮助。不,我找不到解决这个问题的任何东西

谢谢!

HGP占位符:HGPlaceholders Documentation

这是在点击占位符中的按钮时默认打印某些内容的函数如下所示:

@IBAction func sendPlaceholderAction(_ sender: Any) {
   onActionButtonTap?()
   print("Placeholder action button tapped")
}

【问题讨论】:

    标签: swift xcode button


    【解决方案1】:

    我想通了......因为我很愚蠢,所以永远把我带走了。

    在您放置在表格视图所在类的底部的这个函数中处理这些操作:

    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")
            }
        }
    
    }
    

    这是对四个 .default 选项中的每一个进行操作的示例。

    希望这可以帮助其他无法弄清楚的人哈哈!

    旁注:另外一件事,您还必须在 viewDidLoad 中设置 tableView 的 placeholderDelegate。

    tableView.placeholderDelegate = self
    

    如果你不这样做,函数将永远不会执行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-18
      • 2022-07-06
      • 2017-02-26
      • 1970-01-01
      • 2020-07-28
      • 2023-03-22
      相关资源
      最近更新 更多