项目介绍:
StatusProvider
DEMO 下载:
Protocol to handle initial Loadings, Empty Views and Error Handling in a ViewController & views
处理初始加载 Loading,空视图和错误处理中的ViewController和views
Podfile
pod ‘StatusProvider’
Functions
[Objective-C] 查看源文件 复制代码
func show(statusType type: StatusProviderType) func hide(statusType type: StatusProviderType) public enum StatusProviderType { case Loading case Error(error: NSError?, retry: (()->Void)?) case Empty(action: (()->Void)?) case None }
Custom Status View
[Objective-C] 查看源文件 复制代码
class MyCustomEmptyView: UIView { } class MyCustomLoadingView: UIView { } class MyCustomErrorView: UIView, ErrorStatusDisplaying { var error: NSError?{ didSet{ /*do your Sh** */} } var retry: (() -> Void)?{ didSet{ /*do your Sh** */} } } extension YourViewController: StatusProvider { var emptyView: UIView?{ return MyCustomEmtyView() } var loadingView: UIView?{ return MyCustomLoadingView() } var errorView: ErrorStatusDisplaying? { return MyCustomErrorView() } }
How to use?
[Objective-C] 查看源文件 复制代码
extension YourViewController: StatusProvider { } class YourViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() loadDataAsynchron() } func loadDataAsynchron() { show(statusType: .Loading) dispatch_after(dispatch_time( DISPATCH_TIME_NOW, Int64(2.0 * Double(NSEC_PER_SEC))),dispatch_get_main_queue()){ let error = NSError(domain: "my.domain", code: 405, userInfo: [NSLocalizedDescriptionKey : "Oh... fu**"]) self.show(statusType: StatusProviderType.Error(error: error, retry: { self.loadDataAsynchron() })) } } }