Giter Site home page Giter Site logo

teambition / tbemptydataset Goto Github PK

View Code? Open in Web Editor NEW
206.0 14.0 29.0 834 KB

An extension of UITableView/UICollectionView's super class, it will display a placeholder emptyDataSet when the data of tableView/collectionView is empty.

License: MIT License

Swift 98.74% Ruby 1.26%

tbemptydataset's People

Contributors

d-wang avatar hongxinhope avatar horexc avatar kazutoyo-picapp avatar kellybennett avatar zetasq avatar

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

tbemptydataset's Issues

Maintain this repository

Is this repo being maintained?

Add Swift Package Manager,
Reply to this issue,
Update xcodeproj for newer xcode versions.

cell count bug

In TBEmptyDataSet.swift function cellsCount() is not very precise, if there is no method numberOfSections in tableview or collectionview. It has a default section.

UITableView state not maintained properly

If you set datasource at the beginning when your view loads it starts view with empty state and then loads data which is not quite right. To avoid this I am setting datasource once I have data ready to load So that time either it shows data or empty state. 

tableView.emptyDataSetDataSource = self
tableView.updateEmptyDataSetIfNeeded() IMP - Need to call this after setting data source.

How to show emptyDataSet later than reloadData()

I want emptyDataSet to appear when I made a network request and it did fail. (for example if there was no internet connection) Currently I am working with observer pattern. And The observer error will be triggered if there was an error. Then this observer will trigger a function and now I want to show the emptyDataSet with the correct title of the error message.

_ = presenter.groupsError.skip(first: 1).observeNext { message in self.groupsLoadingError(message: message) }

private func groupsLoadingError(message: String)
{
errorMessage = message
_ = tableView.emptyDataSetDelegate?.emptyDataSetShouldDisplay(in: tableView)
}

And at this moment in the groupsLoadingError function it should trigger the emptyDataSet.

How can I do that?

Impossible to override gestureRecognizer shouldRecognizeSimultaneouslyWith method when pod is added

public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool

needs to be

'open func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool'

because you can't override methods that aren't in the same module.

How do I remove the emptydataset?

I call the delegates

Then set title and Description
titleForEmptyDataSet = "No Job"
descripitonForEmptyDataSet = "Tap + to create a new job"

This works perfectly as it should. However when I add a new "job" (a cell to the tableView)
the "No Job Tap + to create a new job" still shows on my tableView.

How do I remove this once there is data to show on the tableView?

CocoaPods supports

Thank you for this nice Swift implementation of the extension.
Are you planning to add Cocoapods supports by any chance?

tb_swizzleCollectionViewReloadData() is called but emptyDataSetShouldDisplay is still displayed

Hi,

Thanks for your library very useful! I have an issue with my collectionView using a fetchedResultsController.

The implement of my NSFetchedResultsControllerDelegate might be the issue with this one… Anyway, if you have any idea how to resolve this that would be good :-).

func emptyDataSetShouldDisplay(scrollView: UIScrollView!) -> Bool {
        guard fetchedResultsController.fetchedObjects?.count == 0 else {
            return false
        }
        return true
    }

Hide method-swizzling logs

This is the output to my console.

tb_swizzleTableViewReloadData
tb_swizzleTableViewEndUpdates
tb_swizzleCollectionViewReloadData
tb_swizzleCollectionViewPerformBatchUpdates

Did you consider to hide these logs when the library is integrated as a dependency?
I'm using Cocoapods and would really appreciate not to see these lines every time I open my app.
Thanks for your great work.

xcode9.3 the button click event can not called

Hi,guy
I find a problem.When I add a button on the custom uitableviewcell, the touch up inside event can not be called. After removing the TBEmptyDataSet from the tableview, the event can be called.

当原来数据为空我获取好数据调用self.tableView.reloadSections(...)这个方法时,这个控件无法正常用

如果我一开始数据为空,这时候会显示默认设置的空时的状态,然后我获得数据,调用self.tableView.reloadSections(...) 或self.collectionView.reloadSections(...)时,这个第三放库就不能正常。得道的结果是,数据正常显示出来,同事加载数据或空状态却不消失。`//
// EmptyDataDemoTableViewController.swift
// TBEmptyDataSetExample
//
// Created by 洪鑫 on 15/11/24.
// Copyright © 2015年 Teambition. All rights reserved.
//

import UIKit
//import TBEmptyDataSet

class EmptyDataDemoTableViewController: UITableViewController, TBEmptyDataSetDataSource, TBEmptyDataSetDelegate {
// MARK: - Structs
private struct CellIdentifier {
static let reuseIdentifier = "Cell"
}

// MARK: - Properties
var indexPath = NSIndexPath()
private var isLoading = false
private var items = [UInt32]()
// MARK: - View life cycle
override func viewDidLoad() {
    super.viewDidLoad()

    navigationItem.title = "TableView"
    tableView.tableFooterView = UIView()
    refreshControl?.addTarget(self, action: "fetchData:", forControlEvents: .ValueChanged)

    tableView.emptyDataSetDataSource = self
    tableView.emptyDataSetDelegate = self

    if indexPath.row != 0 {
        loadData(self)
    }
}

// MARK: - Helper
func fetchData(sender: AnyObject) {
    let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(1.5 * Double(NSEC_PER_SEC)))
    dispatch_after(delayTime, dispatch_get_main_queue()) { () -> Void in
        //            self.tableView.reloadData()
        for _ in 0..<10 {
            self.items.append(arc4random()%1000)
        }
        self.tableView.reloadSections(NSIndexSet(index: 0), withRowAnimation: .Fade)
        self.refreshControl?.endRefreshing()
    }
}

func loadData(sender: AnyObject) {
    isLoading = true
    let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(1.75 * Double(NSEC_PER_SEC)))
    dispatch_after(delayTime, dispatch_get_main_queue()) { () -> Void in
        self.isLoading = false

// for i in 0..<10 {
// self.items.append(String(stringInterpolationSegment:i))
// }
// self.tableView.reloadSections(NSIndexSet(index: 0), withRowAnimation: .Fade)
self.tableView.reloadData()
}
}

// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return 1
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return items.count
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    var cell = tableView.dequeueReusableCellWithIdentifier(CellIdentifier.reuseIdentifier)
    if cell == nil {
        cell = UITableViewCell(style: .Default, reuseIdentifier: CellIdentifier.reuseIdentifier)
    }
    cell!.selectionStyle = .None
    cell?.textLabel?.text = String(stringInterpolationSegment: items[indexPath.row])
    return cell!
}

// MARK: - TBEmptyDataSet data source
func titleForEmptyDataSet(scrollView: UIScrollView!) -> NSAttributedString? {
    let title = EmptyData.titles[indexPath.row]
    var attributes: [String : AnyObject]?
    if indexPath.row == 1 {
        attributes = [NSFontAttributeName: UIFont.systemFontOfSize(22.0), NSForegroundColorAttributeName: UIColor.grayColor()]
    } else if indexPath.row == 2 {
        attributes = [NSFontAttributeName: UIFont.systemFontOfSize(24.0), NSForegroundColorAttributeName: UIColor.grayColor()]
    }
    return NSAttributedString(string: title, attributes: attributes)
}

func descriptionForEmptyDataSet(scrollView: UIScrollView!) -> NSAttributedString? {
    let description = EmptyData.descriptions[indexPath.row]
    var attributes: [String : AnyObject]?
    if indexPath.row == 1 {
        attributes = [NSFontAttributeName: UIFont.systemFontOfSize(17.0), NSForegroundColorAttributeName: UIColor(red: 3 / 255, green: 169 / 255, blue: 244 / 255, alpha: 1)]
    } else if indexPath.row == 2 {
        attributes = [NSFontAttributeName: UIFont.systemFontOfSize(18.0), NSForegroundColorAttributeName: UIColor.purpleColor()]
    }
    return NSAttributedString(string: description, attributes: attributes)
}

func imageForEmptyDataSet(scrollView: UIScrollView!) -> UIImage? {
    return EmptyData.images[indexPath.row]
}

func verticalOffsetForEmptyDataSet(scrollView: UIScrollView!) -> CGFloat {
    if let navigationBar = navigationController?.navigationBar {
        return -navigationBar.frame.height * 0.75
    }
    return 0
}

func customViewForEmptyDataSet(scrollView: UIScrollView!) -> UIView? {
    if isLoading {
        let activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: .Gray)
        activityIndicator.startAnimating()
        return activityIndicator
    }
    return nil
}

// MARK: - TBEmptyDataSet delegate
func emptyDataSetScrollEnabled(scrollView: UIScrollView!) -> Bool {
    return true
}

func emptyDataSetTapEnabled(scrollView: UIScrollView!) -> Bool {
    return true
}

func emptyDataSetShouldDisplay(scrollView: UIScrollView!) -> Bool {
    return true
}

func emptyDataSetWillAppear(scrollView: UIScrollView!) {
     print("EmptyDataSet Will Appear!")
}

func emptyDataSetDidAppear(scrollView: UIScrollView!) {
    print("EmptyDataSet Did Appear!")
}

func emptyDataSetWillDisappear(scrollView: UIScrollView!) {
    print("EmptyDataSet Will Disappear!")
}

func emptyDataSetDidDisappear(scrollView: UIScrollView!) {
    print("EmptyDataSet Did Disappear!")
}

func emptyDataSetDidTapView(scrollView: UIScrollView!) {
    let alert = UIAlertController(title: nil, message: "Did Tap EmptyDataView!", preferredStyle: .Alert)
    let cancelAction = UIAlertAction(title: "OK", style: .Cancel, handler: nil)
    alert.addAction(cancelAction)
    presentViewController(alert, animated: true, completion: nil)
}

}
`

Carthage does not work anymore

*** Fetching TBEmptyDataSet
*** Checking out TBEmptyDataSet at "3.0.2"
*** xcodebuild output can be found in /var/folders/zz/zyxvpxvq6csfxvn_n0000000000000/T/carthage-xcodebuild.AtXJjt.log
*** Building scheme "TBEmptyDataSet" in TBEmptyDataSet.xcworkspace
Build Failed
Task failed with exit code 1:
/usr/bin/xcrun lipo -create /var/root/Library/Caches/org.carthage.CarthageKit/DerivedData/12.3_12C33/TBEmptyDataSet/3.0.2/Build/Intermediates.noindex/ArchiveIntermediates/TBEmptyDataSet/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/TBEmptyDataSet.framework/TBEmptyDataSet /var/root/Library/Caches/org.carthage.CarthageKit/DerivedData/12.3_12C33/TBEmptyDataSet/3.0.2/Build/Products/Release-iphonesimulator/TBEmptyDataSet.framework/TBEmptyDataSet -output /Users/user/Projects/someProject/Carthage/Build/iOS/TBEmptyDataSet.framework/TBEmptyDataSet

This usually indicates that project itself failed to compile. Please check the xcodebuild log for more details: /var/folders/zz/zyxvpxvq6csfxvn_n0000000000000/T/carthage-xcodebuild.AtXJjt.log

Remove Empty Set When Reloading Table Sections

To animate my table view reload I use the following code:

        let range = NSMakeRange(0, self.tableView.numberOfSections)
        let sections = NSIndexSet(indexesIn: range)
        self.tableView.reloadSections(sections as IndexSet, with: .automatic)

But the image and text for the empty state stays on the screen when data is reloaded, How could I solve it? It works only with tableView.reloadData()

Issue with prefersLargeTitles set to true

Hey there, there seems to be an issue when the navigation bar prefersLargeTitles property is set to true. Do you perhaps know why this is happening? I've attached an image. Edit: this is always happening regardless of prefersLargeTitles.

Edit: I installed the framework through Carthage: github "teambition/TBEmptyDataSet".
Edit: it happens on iPhone X and older devices as well.

test3

the WeakObjectContainer

hi! i find a problem the memory leak,the WeakObjectContainer couldnot Call the function deinit

but i donot understand the reason.

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.