GithubHelp home page GithubHelp logo

xiaoye220 / emptydataset-swift Goto Github PK

View Code? Open in Web Editor NEW
675.0 16.0 96.0 2.69 MB

🎄 DZNEmptyDataSet implement with Swift.A drop-in UITableView/UICollectionView superclass category for showing empty datasets whenever the view has no content to display. DZNEmptyDataSet with Swift.

License: MIT License

Ruby 5.48% Swift 93.95% Objective-C 0.57%
swift emptydataset-swift dznemptydataset uicollectionview uitableview

emptydataset-swift's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

emptydataset-swift's Issues

Calling tableView.reloadEmptyDataSet() doesn't animate

Hello.

In my implementation, whenever I delete a row and the tableView will be empty, I call tableView.reloadEmptyDataSet() to show the empty data set background image.

The image appears but it doesn't fadeIn as when the app launches with a blank tableView, it just shows abruptly.

Is there a way to make it always fade in ?

collectionViewSwizzledReloadData Thread 1: EXC_BAD_ACCESS

I'm getting the following error

Thread 1: EXC_BAD_ACCESS (code=2, address=0x16bb3bff8)

in the function

@objc private func collectionViewSwizzledReloadData() {
collectionViewSwizzledReloadData()
reloadEmptyDataSet()
}

Causing my app to crash. It appears that the crash happens on some calls to collectionView.reloadData()

Interestingly, the offensive UICollectionView does not even have EmptyDataSet set up on it. It's just a regular UICollectionView.

customView not display

in customView method ,I return a UIView , the page not display,but return a UIImageView ,it word

返回偏移量不生效

不生效

func verticalOffset(forEmptyDataSet scrollView: UIScrollView) -> CGFloat {
return 100
}

Side effect with JTAppleCalendar

Your framework has a side effect with JTAppleCalendar. When I use EmptyDataSet-Swift and assign it to a tableview (which can be on a completely different UIViewController that an invisible view from EmptyDataSet-Swift is on top of the calendar.

For an example project please see patchthecode/JTAppleCalendar#712

Add support for loading indicator

Empty view may exist due to network speed. It will be useful to distinguish between an empty (or error) state and a loading state and show either empty (error) message or a loading indicator while request is in progress.

emptyDataSetView is not showing correctly when contentInset is set

When contentInset is set for left and right, only left offset is working..
As a result, empty label cannot be centered horizontally.
Below is the code snippet and its screenshot

mCollectionView.contentInset = UIEdgeInsets(top: 0,
                                            left: 50,
                                            bottom: 0,
                                            right: 50)
mCollectionView.backgroundColor = UIColor.red

mCollectionView.emptyDataSetView { (view) in
    view.titleLabelString(Utils.getAttributedString(text: "No photos uploaded yet"))
        .backgroundColor = UIColor.yellow
}

pod 'EmptyDataSet-Swift', '~> 4.2.0' not available

according to instructions version, 4.2.0 is available but I am not able to install it with this version.

  In Podfile:
    EmptyDataSet-Swift (~> 4.2.0)

None of your spec sources contain a spec satisfying the dependency: `EmptyDataSet-Swift (~> 4.2.0)`.```

Usage without confirmation to datasource and/or delegate not working.

Usage without confirmation to datasource and/or delegate.

it says in documentation example that we can simply use empty data set by calling the emptyDataSetView method but in my case I can seem to do it.
It gives error "Value of type 'UITableView' has no member 'emptyDataSetView' "

is there any particular reason for this Do I need any additional settings to make this work

Layout not completed when setting datasource for customView

Quite often, when I return a customView from the datasource, the layout of the collectionView/tableView is not completed.

Very often I have have to set the emptyDataSetSource asynchronously on the main thread to avoid a UI glitch (teleportation of the bottom constraint) if I set the emptyDataSource in the viewDidLoad().
The other alternative I have is to set it in the viewDidLayoutSubviews()

Would there be a way to improve this?

Empty data source does not show when I call deleteRows

I added an empty data source like this:

    collectionView.emptyDataSetView { (view) in
        view.titleLabelString(NSAttributedString(string: "Nothing to see here!"))
        view.shouldDisplay(true)
    }

And I used deleteItems to delete the items one by one. After deleting the last item, I expected the empty data source to show up, but it does not. Bug?

EmptyDataSetSource function not get called on subclass if parent class has not implement that EmptyDataSetSource function

For example, a viewcontroller called ParentVC has implement EmptyDataSetSource with below delegate function.

func title(forEmptyDataSet _: UIScrollView) -> NSAttributedString? {
	return NSAttributedString(string: "title")
}

Now, a viewcontroller called SubVC which inherited ParentVC. if I want to show a button when tableview is empty. I added this delegate method.

func buttonTitle(forEmptyDataSet _: UIScrollView, for _: UIControl.State) -> NSAttributedString? {
	return NSAttributedString(string: "Add")
}

The result is the subclass delegate method will not be called. There is no button shown. This is not I expected.

And I test that if I add the function above at ParentVC and override in SubVC. Then it works.

In ParentVC
func buttonTitle(forEmptyDataSet _: UIScrollView, for _: UIControl.State) -> NSAttributedString? {
	return nil
}
In SubVC
override func buttonTitle(forEmptyDataSet _: UIScrollView, for _: UIControl.State) -> NSAttributedString? {
	return NSAttributedString(string: "Add")
}

It is strange that I need to implement the function into ParentVC which is useless to ParentVC. If I have many different subclass of ParentVC which has their own special handling. I have to add all those method on ParentVC first and override at subclass then.

UIRefreshControl does not work

If I add UIRefreshControl to tableView then I can't pull down to refresh with emptyDataSetView. If I remove emptyDataSetView then it works.

tableView.addSubview(refreshControl)
tableView.emptyDataSetView { view in
            view.image(UIImage(named: "graduation_cap"))
            view.titleLabelString(NSAttributedString(string: "Courses not available yet."))
            view.detailLabelString(NSAttributedString(string: "Pull down to refresh or check back later."))
            view.verticalSpace(20)
        }

不能支持xib

空视图不支持xib,或者sb的展示,当没有数据的时候,只会显示一个空白页

Empty Data Set description text extending beyond the tableview

Steps to reproduce

  1. Create UITableView and add the delegate methods, data source, etc
  2. Set the empty data set title, description, etc
  3. Load the empty data set
  4. Change the description text to something else
  5. Reload the empty data set

What should happen

The description should change to the new text and fit the table view

What happens instead

The description text extends beyond the table view

img_0430

Code

func description(forEmptyDataSet scrollView: UIScrollView) -> NSAttributedString? {
        if (noSearchDone && !searchFound) {
            let myAttribute = [NSAttributedStringKey.font: UIFont.systemFont(ofSize: 18.0), NSAttributedStringKey.foregroundColor: UIColor.lightGray]
            let myString = NSMutableAttributedString(string: "Tap the ", attributes: myAttribute)
            let myStringTwo = NSMutableAttributedString(string: " icon (or press the button below) to search for BROOKESBus timings", attributes: myAttribute)
            let imageAttachment = NSTextAttachment()
            imageAttachment.image = UIImage(named: "SearchIcon")?.maskWithColor(color: UIColor(red: 0.0, green: 0.478431, blue: 1.0, alpha: 1))
            imageAttachment.bounds = CGRect(x: 0, y: 0, width: myString.size().height, height: myString.size().height)
            let imageString = NSAttributedString(attachment: imageAttachment)
            myString.append(imageString)
            myString.append(myStringTwo)
            return myString
        } else if (!noSearchDone && !searchFound) {
            let myString = "No information is available for BROOKESBuses going from \"\(departure)\" to \"\(destination)\" at the moment"
            let myAttribute = [NSAttributedStringKey.font: UIFont.systemFont(ofSize: 18.0), NSAttributedStringKey.foregroundColor: UIColor.lightGray]
            let myAttrString = NSAttributedString(string: myString, attributes: myAttribute)
            return myAttrString
        } else {
            return nil
        }
    }

Delegate and Datasource should be weak

Not having weak delegates can result in retain cycles that cause memory leaks.

extension UIScrollView : UIGestureRecognizerDelegate {

    public var emptyDataSetSource: EmptyDataSetSource?

    public var emptyDataSetDelegate: EmptyDataSetDelegate?

    public var isEmptyDataSetVisible: Bool { get }

    public func emptyDataSetView(_ closure: @escaping (EmptyDataSet_Swift.EmptyDataSetView) -> Void)

    public func reloadEmptyDataSet()
}

should be

extension UIScrollView : UIGestureRecognizerDelegate {

    public weak var emptyDataSetSource: EmptyDataSetSource?

    public weak var emptyDataSetDelegate: EmptyDataSetDelegate?

    public var isEmptyDataSetVisible: Bool { get }

    public func emptyDataSetView(_ closure: @escaping (EmptyDataSet_Swift.EmptyDataSetView) -> Void)

    public func reloadEmptyDataSet()
}

is it possible to add a button with action as a custom view?

I can't get action called with the following code:

func customView(forEmptyDataSet scrollView: UIScrollView) -> UIView? {
    let button = UIButton(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
    button.addTarget(self, action: #selector(hello), for: [.touchUpInside])
    button.backgroundColor = UIColor.red
    return button
}

@objc func hello() {
    print("Hello")
}

CustomView resized to (0,0,0,0)

I load a custom view from xib or storyboard. The view's frame and bounds are resized to (0,0,0,0), so none of the subview controls are interactive.

Custom View For Collection View With Header

Hi, I would like your help on how I can go about creating a custom view for a collection view that has a header. I need a to create a custom view otherwise the default empty data set view would cover the header as well, and users won't be able to interact with the elements on the header (if there is a way to make the default empty data set view not to cover the header that would be great). Else, how could I get the y coordinate for custom view so it starts where header ends (y coordinate in CGRect method initialization). Thanks a lot.

Below is a screenshot of the collection view.

Screen Shot 2021-10-19 at 9 45 21 AM

remove tableview lines

Is it possible to remove the table view lines by your framework? Currently the label is renderd on top of the empty tableview. I would prefer a setting where your framework would hide the empty tableview. Perhaps you already have this option but I couldn't find it. Thanks

bildschirmfoto 2017-12-14 um 08 34 53

emptyDataSetSource和emptyDataSetDelegate 在声明时对循环引用一点的疑问?

在项目源码中在声明emptyDataSetSource和emptyDataSetDelegate的时候为啥不需要加 weak?
项目中是:
public var emptyDataSetSource: EmptyDataSetSource?
public var emptyDataSetDelegate: EmptyDataSetDelegate?

为什么不设置为
public weak var emptyDataSetSource: EmptyDataSetSource?
public weak var emptyDataSetDelegate: EmptyDataSetDelegate?

还望大佬讲解一下?谢谢~

布局问题

button的布局不能自定义,大小不是我想要的,想自己定义
2018-05-06 5 52 20
2018-05-06 5 52 56

自定义视图 为什么只能响应一个action呢

`

func customView(forEmptyDataSet scrollView: UIScrollView) -> UIView? {

    let view = UIView.init(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 180))
    
    let addBtn = UIButton()
    addBtn.setImage(UIImage.init(named: "添加设备开启无痛人生big"), for: .normal)
    addBtn.addTarget(self, action: #selector(emptyAddDevice), for: .touchUpInside)
    view.addSubview(addBtn)
    addBtn.snp.makeConstraints { make in
        make.top.equalTo(view).offset(20)
        make.center.equalTo(view)
    }
    
    let btnBotLab = UILabel()
    btnBotLab.text = "add_device".localized()
    btnBotLab.font = UIFont.boldSystemFont(ofSize: 18)
    btnBotLab.textColor = kAppMainColor
    btnBotLab.textAlignment = .center
    view.addSubview(btnBotLab)
    btnBotLab.snp.makeConstraints { make in
        make.top.equalTo(addBtn.snp_bottomMargin)
        make.left.right.equalTo(view)
        make.height.equalTo(20)
    }
    
    let introBtn = UIButton()
    introBtn.setTitle("pulse_intro".localized(), for: .normal)
    introBtn.setTitleColor(.darkGray, for: .normal)
    introBtn.titleLabel?.font = .boldSystemFont(ofSize: 14)
    introBtn.addTarget(self, action: #selector(emptyShowIntro), for: .touchUpInside)
    view.addSubview(introBtn)
    introBtn.snp.makeConstraints { (m) in
        m.top.equalTo(btnBotLab.snp_bottomMargin).offset(30)
        m.centerX.equalTo(view)
        m.height.equalTo(20)
    }
    
    let introBtnBotLine = UIView()
    introBtnBotLine.backgroundColor = .darkGray
    view.addSubview(introBtnBotLine)
    introBtnBotLine.snp.makeConstraints { (m) in
        m.left.equalTo(introBtn.snp_leftMargin).offset(0)
        m.right.equalTo(introBtn.snp_rightMargin).offset(0)
        m.top.equalTo(introBtn.snp_bottomMargin).offset(4)
        m.height.equalTo(1)
    }
    
    return view
    
}

@objc func emptyAddDevice() {
    print(message: "didTapButton 添加设备")
    let scanVC = ScanDevicesVC()
    scanVC.hidesBottomBarWhenPushed = true
    self.navigationController?.pushViewController(scanVC, animated: true)
}

@objc func emptyShowIntro() {
    let vc = ProductInfoVC()
    vc.hidesBottomBarWhenPushed = true
    vc.productIndex = self.productIndex
    self.navigationController?.pushViewController(vc, animated: true)
}

`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.