TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Dec 2014 |
Maintained by Unclaimed.
Most applications display lists of content (datasets), which many turn out to be empty at one point, specially for new users with blank accounts. Empty screens create confusion by not being clear about what's going on, if there is an error/bug or if the user is supposed to do something within your app to be able to consume the content.
Empty Datasets are helpful for:
This library has been designed in a way where you won't need to use an extended UITableView class. It will still work when using UITableViewController. By simply conforming to the datasource and delegate you will be able to fully customize the content and appearance of the empty datasets for your application.
Available in Cocoa Pods
pod 'UITableView-DataSet'
For complete documentation, visit CocoaPods' auto-generated doc
#import "UITableView+DataSet.h"
Conform to datasource and/or delegate.
@interface MainViewController : UITableViewController <DZNTableViewDataSetSource, DZNTableViewDataSetDelegate>
Return the content you want to show on the empty datasets, and take advantage of NSAttributedString features to fully customise the text appearance.
- (NSAttributedString *)titleForTableViewDataSet:(UITableView *)tableView {
NSString *text = @"Please Allow Photo Access";
NSDictionary *attributes = @{NSFontAttributeName: [UIFont boldSystemFontOfSize:18.0],
NSForegroundColorAttributeName: [UIColor darkGrayColor]};
return [[NSAttributedString alloc] initWithString:text attributes:attributes];
}
- (NSAttributedString *)descriptionForTableViewDataSet:(UITableView *)tableView {
NSString *text = @"This allows you to share photos from your library and save photos to your camera roll.";
NSMutableParagraphStyle *paragraph = [NSMutableParagraphStyle new];
paragraph.lineBreakMode = NSLineBreakByWordWrapping;
paragraph.alignment = NSTextAlignmentCenter;
NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:14.0],
NSForegroundColorAttributeName: [UIColor lightGrayColor],
NSParagraphStyleAttributeName: paragraph};
return [[NSAttributedString alloc] initWithString:text attributes:attributes];
}
- (NSAttributedString *)buttonTitleForTableViewDataSet:(UITableView *)tableView forState:(UIControlState)state {
NSDictionary *attributes = @{NSFontAttributeName: [UIFont boldSystemFontOfSize:17.0]
return [[NSAttributedString alloc] initWithString:@"Continue" attributes:attributes];
}
Return the behaviours you would expect from the empty datasets, and receive the user events.
- (BOOL)tableViewDataSetShouldAllowTouch:(UITableView *)tableView {
return YES;
}
- (BOOL)tableViewDataSetShouldAllowScroll:(UITableView *)tableView {
return YES;
}
- (void)tableViewDataSetDidTapView:(UITableView *)tableView {
}
- (void)tableViewDataSetDidTapButton:(UITableView *)tableView {
}
It is very important to set the dataSetSource and dataSetDelegate to nil, on the viewcontroller's -dealloc method. Since this library uses KVO under the hood, the observer must be removed when the tableview is going to be released.
- (void)dealloc
{
self.tableView.dataSetSource = nil;
self.tableView.dataSetDelegate = nil;
}
This sample project replicates several popular application's empty datasets (~20) with their exact content and appearance, such as Airbnb, Dropbox, Facebook, Foursquare, and many others. Use this project for understanding how easy and flexible it is to customize the appearance of your empty datasets.
This other sample project shows a list of the world countries. By searching, it autocompletes and when no content is matched, a simple empty dataset is shown. Use this project for understanding better the interaction between the UITableViewDataSource and the DZNTableDataSetSource protocols.
I tried to build an easy to use API, while beeing flexible enough for multiple variations, but I'm sure there are ways of improving and adding more features, so feel free to collaborate with ideas, issues and/or pull requests.
(The MIT License)
Copyright (c) 2014 Ignacio Romero Zurbuchen [email protected]
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.