Skip to content

Commit

Permalink
improve tableView example
Browse files Browse the repository at this point in the history
  • Loading branch information
hongxinhope committed Feb 24, 2016
1 parent ab7c6cb commit eca254c
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions Example/EmptyDataDemoTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class EmptyDataDemoTableViewController: UITableViewController, TBEmptyDataSetDat
// MARK: - Properties
var indexPath = NSIndexPath()
private var isLoading = false
private var dataCount = 0

// MARK: - View life cycle
override func viewDidLoad() {
Expand All @@ -39,6 +40,7 @@ class EmptyDataDemoTableViewController: UITableViewController, TBEmptyDataSetDat
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.dataCount = 7
self.tableView.reloadData()
self.refreshControl?.endRefreshing()
}
Expand All @@ -53,25 +55,33 @@ class EmptyDataDemoTableViewController: UITableViewController, TBEmptyDataSetDat
}
}

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

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 0
return dataCount
}

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 = UITableViewCell(style: .Value1, reuseIdentifier: CellIdentifier.reuseIdentifier)
}
cell!.selectionStyle = .None

cell!.textLabel?.text = "Cell"
cell!.detailTextLabel?.text = "Click to delete"
return cell!
}

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
tableView.deselectRowAtIndexPath(indexPath, animated: true)
tableView.beginUpdates()
dataCount--
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
tableView.endUpdates()
}

// MARK: - TBEmptyDataSet data source
func titleForEmptyDataSet(scrollView: UIScrollView!) -> NSAttributedString? {
let title = EmptyData.titles[indexPath.row]
Expand Down

0 comments on commit eca254c

Please sign in to comment.