Topics

#14: DZNEmptyDataSet 🐚

Topics

DZNEmptyDataSet is a library that makes it extremely easy to add custom "empty" data sets, for when a screen in your app either currently has no data, or the user hasn’t created any data yet.

You can configure it by implementing a bunch of different optional methods in the DZNEmptyDataSet protocol. A pretty simple setup is shown here, but the there are lots of more advanced options including custom views and even easily adding a button below the text.

extension PhotosViewController : DZNEmptyDataSetSource {
  func titleForEmptyDataSet(scrollView: UIScrollView!) -> NSAttributedString! {
    return NSAttributedString(string: "No Photos")
  }

  func descriptionForEmptyDataSet(scrollView: UIScrollView!) -> NSAttributedString! {
    let text = "Photos you take will appear here"

    return NSAttributedString(string: text, attributes: [
      NSForegroundColorAttributeName: UIColor.grayColor()
    ])
  }

  func imageForEmptyDataSet(scrollView: UIScrollView!) -> UIImage! {
    return UIImage(named: "cracked-egg")
  }
}

Detect interaction by implementing one of the methods in the DZNEmptyDataSetDelegate protocol.

extension PhotosViewController : DZNEmptyDataSetDelegate {
  func emptyDataSetDidTapButton(scrollView: UIScrollView!) {
    println("tapped button on the empty view!")
  }
}

Here's some example empty screens DZNEmptyDataSet can help you create:

Example Project

You can download a complete working project here

More Info

More info about DZNEmptyDataSet can be found at git.io/empty