ErrorKing 0.2.0

ErrorKing 0.2.0

测试已测试
Lang语言 SwiftSwift
许可证 MIT
Release上次发布2017年4月
SwiftSwift 版本3.0
SPM支持 SPM

Bruno RochaBrunoRocha 维护。



ErrorKing 0.2.0

  • 作者
  • rockbruno

ErrorKing

让您仅通过协议继承就能在 View Controllers 上实现智能错误提示和完整的空状态视图。

要将 ErrorKing 添加到 ViewController 中,请对其进行扩展 ErrorProne 协议

extension MyViewController: ErrorProne {}

这就行了!您现在可以调用 ViewController 的新属性:`errorKing`,并看到它的效果。

self.errorKing.setError(title: "Damn!", description: "Sorry for that.", emptyStateText: "Something happened :(")

现在,当 ViewController 下一次可见时(例如用户触发了加载但推送了另一个屏幕),ErrorKing 将显示

Error EmptyState

额外定制

要定义当空状态的重新加载按钮被触摸时会发生什么,请重写 ErrorProneerrorKingEmptyStateReloadButtonTouched

extension MyViewController: ErrorProne {
    func errorKingEmptyStateReloadButtonTouched() {
        //load my stuff again
        errorKing.errorKingEmptyStateReloadButtonTouched() //This will remove the empty state from the screen.
    }
}

您还可以编写在显示空状态之前发生的事件

func actionBeforeDisplayingErrorKingEmptyState() {
    //do something before displaying the empty state screen, like disabling your tableView's scrolling
    errorKing.actionBeforeDisplayingErrorKingEmptyState() //Sets up and displays the empty state screen.
}

…并且根据需要更改空状态的大小

self.errorKing?.setEmptyStateFrame(rect: aFrame)

提供自定义 EmptyState 屏幕

要添加您的自定义空状态视图,只需创建一个具有 ErrorKingEmptyStateView 作为类或超类的 .swift/.xib 文件,并连接相应的出口,如果使用了 .xib,或者设置 errorLabel 并初始化一个触发 tryAgain: 的按钮,如果您使用视图代码。然后,调用

self.errorKing.setEmptyStateView(toView: myCustomEmptyState)

您可以在示例项目中查看它的作用。

ExampleEmptyState

安装

作者

rockbruno,[email protected]

许可证

ErrorKing 可在 MIT 许可下使用。有关更多信息,请参阅 LICENSE 文件。