|
@@ -8,15 +8,22 @@
|
|
|
|
|
|
import Foundation
|
|
|
|
|
|
+@objc public protocol NCEmptyDataSetDelegate {
|
|
|
+ @objc optional func emptyDataSetView(_ view: NCEmptyView)
|
|
|
+}
|
|
|
+
|
|
|
class NCEmptyDataSet: NSObject {
|
|
|
|
|
|
var emptyView: NCEmptyView?
|
|
|
+ var delegate: NCEmptyDataSetDelegate?
|
|
|
+
|
|
|
|
|
|
- init(view: UIView, image: UIImage?, title: String, description: String, offset: CGFloat) {
|
|
|
+ init(view: UIView, image: UIImage?, title: String, description: String, offset: CGFloat = 0, delegate: NCEmptyDataSetDelegate?) {
|
|
|
super.init()
|
|
|
|
|
|
if let emptyView = UINib(nibName: "NCEmptyView", bundle: nil).instantiate(withOwner: self, options: nil).first as? NCEmptyView {
|
|
|
|
|
|
+ self.delegate = delegate
|
|
|
self.emptyView = emptyView
|
|
|
|
|
|
emptyView.frame = CGRect(x:0, y: 0, width:300, height:300)
|
|
@@ -24,9 +31,11 @@ class NCEmptyDataSet: NSObject {
|
|
|
emptyView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
|
|
emptyView.emptyImage.image = image
|
|
|
- emptyView.emptyTtle.text = NSLocalizedString(title, comment: "")
|
|
|
+ emptyView.emptyTitle.text = NSLocalizedString(title, comment: "")
|
|
|
+ emptyView.emptyTitle.sizeToFit()
|
|
|
emptyView.emptyDescription.text = NSLocalizedString(description, comment: "")
|
|
|
-
|
|
|
+ emptyView.emptyDescription.sizeToFit()
|
|
|
+
|
|
|
view.addSubview(emptyView)
|
|
|
|
|
|
let constantY: CGFloat = (view.frame.height - emptyView.frame.height) / 2 - offset
|
|
@@ -37,6 +46,9 @@ class NCEmptyDataSet: NSObject {
|
|
|
}
|
|
|
|
|
|
func numberOfItemsInSection(_ numberItems: Int) {
|
|
|
+ if let emptyView = emptyView {
|
|
|
+ self.delegate?.emptyDataSetView?(emptyView)
|
|
|
+ }
|
|
|
if numberItems == 0 {
|
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
|
|
|
self.emptyView?.isHidden = false
|
|
@@ -49,10 +61,10 @@ class NCEmptyDataSet: NSObject {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-class NCEmptyView: UIView {
|
|
|
+public class NCEmptyView: UIView {
|
|
|
|
|
|
@IBOutlet weak var emptyImage: UIImageView!
|
|
|
- @IBOutlet weak var emptyTtle: UILabel!
|
|
|
+ @IBOutlet weak var emptyTitle: UILabel!
|
|
|
@IBOutlet weak var emptyDescription: UILabel!
|
|
|
}
|
|
|
|