Skip to content

Commit

Permalink
readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Xin Hong committed Nov 26, 2015
1 parent 04e1832 commit dedc5db
Show file tree
Hide file tree
Showing 13 changed files with 224 additions and 62 deletions.
12 changes: 12 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
disabled_rules: # rule identifiers to exclude from running
- line_length
- nesting
included: # paths to include during linting. `--path` is ignored if present. takes precendence over `excluded`.
excluded: # paths to ignore during linting. overridden by `included`.
- Carthage
# parameterized rules can be customized from this configuration file
line_length: 150
# parameterized rules are first parameterized as a warning level, then error level.
type_body_length:
- 300 # warning
- 400 # error
12 changes: 12 additions & 0 deletions Example/.swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
disabled_rules: # rule identifiers to exclude from running
- line_length
- nesting
included: # paths to include during linting. `--path` is ignored if present. takes precendence over `excluded`.
excluded: # paths to ignore during linting. overridden by `included`.
- Carthage
# parameterized rules can be customized from this configuration file
line_length: 150
# parameterized rules are first parameterized as a warning level, then error level.
type_body_length:
- 300 # warning
- 400 # error
15 changes: 5 additions & 10 deletions Example/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,29 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
return true
}

func applicationWillResignActive(application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.

}

func applicationDidEnterBackground(application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

}

func applicationWillEnterForeground(application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.

}

func applicationDidBecomeActive(application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

}

func applicationWillTerminate(application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

}

}

18 changes: 9 additions & 9 deletions Example/DemoViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ class DemoViewController: UITableViewController {
static let examples = ["Empty Photos", "Empty Events", "Empty Message"]
static let sectionTitles = ["TableView", "CollectionView"]
}

private struct SegueIdentifier {
static let showTableView = "ShowEmptyDataDemoTableView"
static let showCollectionView = "ShowEmptyDataDemoCollectionView"
}

private struct CellIdentifier {
static let reuseIdentifier = "Cell"
}

// MARK: - Properties
var selectedIndexPath = NSIndexPath()

// MARK: - View life cycle
override func viewDidLoad() {
super.viewDidLoad()
Expand All @@ -52,11 +52,11 @@ class DemoViewController: UITableViewController {
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return Data.examples.count
}

override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return Data.sectionTitles[section]
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier(CellIdentifier.reuseIdentifier)
if cell == nil {
Expand All @@ -67,18 +67,18 @@ class DemoViewController: UITableViewController {

return cell!
}

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
selectedIndexPath = indexPath
if indexPath.section == 0 {
performSegueWithIdentifier(SegueIdentifier.showTableView, sender: self)
} else if indexPath.section == 1 {
performSegueWithIdentifier(SegueIdentifier.showCollectionView, sender: self)
}

tableView.deselectRowAtIndexPath(indexPath, animated: true)
}

// MARK: - Navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == SegueIdentifier.showTableView {
Expand Down
48 changes: 24 additions & 24 deletions Example/EmptyDataDemoCollectionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,26 @@ class EmptyDataDemoCollectionViewController: UICollectionViewController, TBEmpty
private struct CellIdentifier {
static let reuseIdentifier = "Cell"
}

// MARK: - Properties
var indexPath = NSIndexPath()
private var isLoading = false

// MARK: - View life cycle
override func viewDidLoad() {
super.viewDidLoad()

navigationItem.title = "CollectionView"
collectionView!.emptyDataSetDataSource = self
collectionView!.emptyDataSetDelegate = self
collectionView!.backgroundColor = UIColor.whiteColor()
collectionView!.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: CellIdentifier.reuseIdentifier)

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

// MARK: - Helper
func loadData(sender: AnyObject) {
isLoading = true
Expand All @@ -42,7 +42,7 @@ class EmptyDataDemoCollectionViewController: UICollectionViewController, TBEmpty
self.collectionView!.reloadData()
}
}

// MARK: - Collection view data source
override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 0
Expand All @@ -54,10 +54,10 @@ class EmptyDataDemoCollectionViewController: UICollectionViewController, TBEmpty

override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(CellIdentifier.reuseIdentifier, forIndexPath: indexPath)

return cell
}

// MARK: - TBEmptyDataSet data source
func titleForEmptyDataSet(scrollView: UIScrollView!) -> NSAttributedString? {
let title = EmptyData.titles[indexPath.row]
Expand All @@ -69,7 +69,7 @@ class EmptyDataDemoCollectionViewController: UICollectionViewController, TBEmpty
}
return NSAttributedString(string: title, attributes: attributes)
}

func descriptionForEmptyDataSet(scrollView: UIScrollView!) -> NSAttributedString? {
let description = EmptyData.descriptions[indexPath.row]
var attributes: [String : AnyObject]?
Expand All @@ -80,28 +80,28 @@ class EmptyDataDemoCollectionViewController: UICollectionViewController, TBEmpty
}
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 backgroundColorForEmptyDataSet(scrollView: UIScrollView!) -> UIColor? {
return UIColor(white: 0.95, alpha: 1)
}

func customViewForEmptyDataSet(scrollView: UIScrollView!) -> UIView? {
let loadingView: UIView = {
let loadingImageView = UIImageView(image: UIImage(named: "loading")!)
let view = UIView(frame: loadingImageView.frame)
view.addSubview(loadingImageView)

let animation: CABasicAnimation = {
let animation = CABasicAnimation(keyPath: "transform")
animation.fromValue = NSValue(CATransform3D: CATransform3DIdentity)
Expand All @@ -112,46 +112,46 @@ class EmptyDataDemoCollectionViewController: UICollectionViewController, TBEmpty
return animation
}()
loadingImageView.layer.addAnimation(animation, forKey: "loading")

return view
}()

if isLoading {
return loadingView
} else {
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)
Expand Down
38 changes: 19 additions & 19 deletions Example/EmptyDataDemoTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,35 @@ class EmptyDataDemoTableViewController: UITableViewController, TBEmptyDataSetDat
private struct CellIdentifier {
static let reuseIdentifier = "Cell"
}

// MARK: - Properties
var indexPath = NSIndexPath()
private var isLoading = false

// 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.refreshControl?.endRefreshing()
}
}

func loadData(sender: AnyObject) {
isLoading = true
let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(1.75 * Double(NSEC_PER_SEC)))
Expand Down Expand Up @@ -81,7 +81,7 @@ class EmptyDataDemoTableViewController: UITableViewController, TBEmptyDataSetDat
}
return NSAttributedString(string: title, attributes: attributes)
}

func descriptionForEmptyDataSet(scrollView: UIScrollView!) -> NSAttributedString? {
let description = EmptyData.descriptions[indexPath.row]
var attributes: [String : AnyObject]?
Expand All @@ -92,18 +92,18 @@ class EmptyDataDemoTableViewController: UITableViewController, TBEmptyDataSetDat
}
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)
Expand All @@ -112,36 +112,36 @@ class EmptyDataDemoTableViewController: UITableViewController, TBEmptyDataSetDat
}
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)
Expand Down
Loading

0 comments on commit dedc5db

Please sign in to comment.