 extension IssueViewController: UITableViewDataSource {
     
     func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
-        return IssueViewSection(rawValue: section)?.numberOfRowsInSection(viewModel) ?? 0
+        return IssueViewSection(rawValue: section).map {
+            switch $0 {
+            case .Info: return viewModel?.issue.value?.info.milestone == nil ? 0 : 1
+            case .Labels: return viewModel?.issue.value?.info.labels.count ?? 0
+            }
+        } ?? 0
     }
 
     func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
-        return IssueViewSection(rawValue: indexPath.section)?.cellForRow(viewModel, indexPath: indexPath) ?? UITableViewCell()
+        return IssueViewSection(rawValue: indexPath.section).flatMap {
+            switch $0 {
+            case .Info:
+                let cell = UIView.getInstance(MilestoneCellView.self)
+                if let milestone = viewModel?.issue.value?.info.milestone {
+                    cell?.bind(milestone)
+                }
+                return cell
+            case .Labels:
+                let cell = UIView.getInstance(LabelCellView.self)
+                if let label = viewModel?.issue.value?.info.labels.safeIndex(indexPath.item) {
+                    cell?.bind(label)
+                }
+                return cell
+            }
+        } ?? UITableViewCell()
     }
     
 

    case Info = 0
    case Labels = 1
    
    func numberOfRowsInSection(viewModel: IssueViewModel?) -> Int {
        switch self {
        case .Info: return viewModel?.issue.value?.info.milestone == nil ? 0 : 1
        case .Labels: return viewModel?.issue.value?.info.labels.count ?? 0
        }
    }
    
    var heightForRow: CGFloat {
        switch self {
        case .Info: return 82
        case .Labels: return 75
        }
    }
    
    func cellForRow(viewModel: IssueViewModel?, indexPath: NSIndexPath) -> UITableViewCell? {
        switch self {
        case .Info:
            let cell = UIView.getInstance(MilestoneCellView.self)
            if let milestone = viewModel?.issue.value?.info.milestone {
                cell?.bind(milestone)
            }
            return cell
        case .Labels:
            let cell = UIView.getInstance(LabelCellView.self)
            if let label = viewModel?.issue.value?.info.labels.safeIndex(indexPath.item) {
                cell?.bind(label)
            }
            return cell
        }
    }
    
    func viewForHeader(viewModel: IssueViewModel?) -> UIView? {
        switch self {
        case .Info:
            let cell = UIView.getInstance(IssueInfoCellView.self)
            if let issue = viewModel?.issue.value {
                cell?.bind(issue)
            }
            return cell
        case .Labels:
            let cell = UIView.getInstance(HeaderCellView.self)
            cell?.bind("Labels")
            return cell
        }
    }
    
    var heightForHeaderInSection: CGFloat {
        switch self {
        case .Info: return 210
        case .Labels: return 56
        }
    }
    
}

extension IssueViewController: UITableViewDelegate {
    
    func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return IssueViewSection(rawValue: section).map {
            switch $0 {
            case .Info: return 210
            case .Labels: return 56
            }
            } ?? 0
    }
    
    func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        return IssueViewSection(rawValue: section).flatMap { sec in
            switch sec {
            case .Info:
                let cell = UIView.getInstance(IssueInfoCellView.self)
                if let issue = self.viewModel?.issue.value {
                    cell?.bind(issue)
                }
                return cell
            case .Labels:
                let cell = UIView.getInstance(HeaderCellView.self)
                cell?.bind("Labels")
                return cell
            }
        }
    }
    
    func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        return IssueViewSection(rawValue: indexPath.section).map {
            switch $0 {
            case .Info: return 82
            case .Labels: return 75
            }
        } ?? 0
    }
    
}
