         tableView.deselectRowAtIndexPath(indexPath, animated: true)
     }
     
+    func scrollViewDidScroll(scrollView: UIScrollView) {
+        let offset = scrollView.contentOffset
+        let bounds = scrollView.bounds
+        let size = scrollView.contentSize
+        let inset = scrollView.contentInset
+        
+        let y = offset.y + bounds.size.height - inset.bottom
+        let h = size.height
+        
+        let reloadDistance: CGFloat = 10
+        if y > h + reloadDistance && !scrolledToBottom {
+            scrolledToBottom = true
+            fetchPosts()
+        }
+    }
+    
     // MARK: UIViewController
     
     override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {

    // MARK: IBActions
    
    @IBAction func changePostFilter(sender: UISegmentedControl) {
        switch sender.selectedSegmentIndex {
        case 0:
            postFilter = .Top
            fetchPosts()
        case 1:
            postFilter = .New
            fetchPosts()
        case 2:
            postFilter = .Ask
            fetchPosts()
        default:
            println("Bad segment index!")
        }
    }
}

    }
    
    func fetchPosts() {
        UIApplication.sharedApplication().networkActivityIndicatorVisible = true
        
        let postUrlAddition = HNManager.sharedManager().postUrlAddition
        if !scrolledToBottom {
            HNManager.sharedManager().loadPostsWithFilter(postFilter, { posts, _ in
                if posts.count > 0 {
                    self.posts = posts as [HNPost]
                    dispatch_async(dispatch_get_main_queue(), {
                        self.tableView.scrollRectToVisible(CGRectMake(0, 0, 1, 1), animated: false)
                        self.tableView.reloadData()
                        self.refreshControl.endRefreshing()
                        UIApplication.sharedApplication().networkActivityIndicatorVisible = false
                    })
                } else {
                    println("Could not fetch posts!")
                    self.refreshControl.endRefreshing()
                    UIApplication.sharedApplication().networkActivityIndicatorVisible = false
                }
            })
        } else if postUrlAddition != nil { // Swift makes me keep the "== true"...
            HNManager.sharedManager().loadPostsWithUrlAddition(postUrlAddition, { posts, _ in
                if posts.count > 0 {
                    self.posts.extend(posts as [HNPost])
                    dispatch_async(dispatch_get_main_queue(), {
                        self.tableView.reloadData()
                        self.tableView.flashScrollIndicators()
                        self.scrolledToBottom = false
                        self.refreshControl.endRefreshing()
                        UIApplication.sharedApplication().networkActivityIndicatorVisible = false
                    })
                } else {
                    println("Could not fetch posts!")
                    self.scrolledToBottom = false
                    self.refreshControl.endRefreshing()
                    UIApplication.sharedApplication().networkActivityIndicatorVisible = false
                }
            })
        }
    }
    
    func stylePostCellAsRead(cell: UITableViewCell) {
