Skip to content

Commit

Permalink
Loading/null state for comments table view
Browse files Browse the repository at this point in the history
  • Loading branch information
weiran committed Jan 10, 2016
1 parent a3a7a95 commit 5afb28f
Show file tree
Hide file tree
Showing 20 changed files with 1,917 additions and 129 deletions.
22 changes: 15 additions & 7 deletions Client/Post/CommentsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import Foundation
import UIKit
import SafariServices

class CommentsViewController : UIViewController, UITableViewDelegate, UITableViewDataSource, CommentDelegate, SFSafariViewControllerDelegate, PostTitleViewDelegate {
class CommentsViewController : UIViewController, UITableViewDelegate, UITableViewDataSource, CommentDelegate, SFSafariViewControllerDelegate, PostTitleViewDelegate, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate {
var post: HNPost?

var comments: [CommentModel] = [CommentModel]() {
var comments: [CommentModel]? {
didSet {
commentsController.comments = comments
commentsController.comments = comments!
}
}

Expand All @@ -30,11 +30,11 @@ class CommentsViewController : UIViewController, UITableViewDelegate, UITableVie
setupPostTitleView()
tableView.estimatedRowHeight = 44.0
tableView.rowHeight = UITableViewAutomaticDimension
tableView.emptyDataSetSource = self;
tableView.emptyDataSetDelegate = self;

commentsController = CommentsController()
if comments.count == 0 {
loadComments()
}
loadComments()
}

override func viewWillAppear(animated: Bool) {
Expand Down Expand Up @@ -70,7 +70,7 @@ class CommentsViewController : UIViewController, UITableViewDelegate, UITableVie
}
}

// MARK - UITableViewDataSource
// MARK: - UITableViewDataSource

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return commentsController.visibleComments.count
Expand All @@ -93,6 +93,14 @@ class CommentsViewController : UIViewController, UITableViewDelegate, UITableVie
return cell
}

// MARK: - DZNEmptyDataSet

func titleForEmptyDataSet(scrollView: UIScrollView!) -> NSAttributedString! {
return comments == nil ? NSAttributedString(string: "Loading comments") : NSAttributedString(string: "No comments")
}

// MARK: - Cell Actions

func commentTapped(sender: UITableViewCell) {
let indexPath = tableView.indexPathForCell(sender)
toggleCellVisibilityForCell(indexPath)
Expand Down
1 change: 1 addition & 0 deletions Client/Supporting Files/Hackers2-Bridging-Header.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
//

#import <libHN/libHN.h>
#import <DZNEmptyDataSet/UIScrollView+EmptyDataSet.h>
1 change: 1 addition & 0 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ platform :ios, '8.0'
source 'https://github.com/CocoaPods/Specs.git'

pod 'libHN'
pod 'DZNEmptyDataSet'
3 changes: 3 additions & 0 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
PODS:
- DZNEmptyDataSet (1.7.3)
- libHN (4.1.0)

DEPENDENCIES:
- DZNEmptyDataSet
- libHN

SPEC CHECKSUMS:
DZNEmptyDataSet: dd7cca17c1d07dfa78956859b1e70a52505678ef
libHN: ec0205556a35d760b5b6a7804699f67276d6633a

COCOAPODS: 0.39.0
9 changes: 9 additions & 0 deletions Pods/DZNEmptyDataSet/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

291 changes: 291 additions & 0 deletions Pods/DZNEmptyDataSet/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5afb28f

Please sign in to comment.