-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathHomeViewController.swift
97 lines (76 loc) · 3.29 KB
/
HomeViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//
// FirstViewController.swift
// TechStacks
//
// Created by Demis Bellot on 2/2/15.
// Copyright (c) 2015 ServiceStack LLC. All rights reserved.
//
import UIKit
class HomeViewController: UIViewController, UITableViewDelegate, UITableViewDataSource,
UIPickerViewDataSource, UIPickerViewDelegate
{
@IBOutlet weak var tblView: UITableView!
@IBOutlet weak var technologyPicker: UIPickerView!
var selectedTechnology:TechnologyTier?
override func viewWillAppear(animated: Bool) {
}
override func viewDidLoad() {
super.viewDidLoad()
self.addLogo()
tblView.delegate = self
tblView.dataSource = self
technologyPicker.delegate = self
technologyPicker.dataSource = self
self.appData.observe(self, properties: [AppData.Property.TopTechnologies, AppData.Property.AllTiers])
self.appData.loadOverview()
}
override func observeValueForKeyPath(keyPath: String, ofObject object: AnyObject, change: [NSObject : AnyObject], context: UnsafeMutablePointer<Void>) {
switch keyPath {
case AppData.Property.AllTiers:
self.technologyPicker.reloadAllComponents()
case AppData.Property.TopTechnologies:
self.tblView.reloadData()
default: break
}
}
deinit { self.appData.unobserve(self) }
var selectedTechnologies:[TechnologyInfo] {
return selectedTechnology == nil
? appData.topTechnologies
: appData.topTechnologies.filter { $0.tier! == self.selectedTechnology! }
}
/* PickerView */
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return appData.allTiers.count
}
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String! {
return appData.allTiers[row].title
}
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
self.selectedTechnology = appData.allTiers[row].value
tblView.reloadData()
}
/* TableView */
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return selectedTechnologies.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = self.tblView.dequeueReusableCellWithIdentifier("cellHome") as? UITableViewCell
?? UITableViewCell()
cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator
let tech = selectedTechnologies[indexPath.row]
cell.textLabel?.text = "\(tech.name!) (\(tech.stacksCount!))"
cell.textLabel!.font = cell.textLabel!.font.fontWithSize(Style.tableCellTitleSize)
return cell
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return Style.tableCellHeight
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let selected = selectedTechnologies[indexPath.row]
self.navigationController?.openTechnology(selected.slug!)
}
}