-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogView.swift
More file actions
81 lines (65 loc) · 2.99 KB
/
LogView.swift
File metadata and controls
81 lines (65 loc) · 2.99 KB
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
//
// LogView.swift
// Historicus
//
// Created by Lance Walker on 7/10/15.
// Copyright © 2015 Lance Walker. All rights reserved.
//
import Foundation
import UIKit
class LogView: UITableViewController, UISearchResultsUpdating {
//Elements
var swiftArray = LogArray as NSArray as! [String]
var filteredDateStrings = [String]()
var resultSearchController = UISearchController()
override func viewDidLoad() {
super.viewDidLoad()
self.resultSearchController = UISearchController(searchResultsController: nil)
self.resultSearchController.searchResultsUpdater = self
self.resultSearchController.dimsBackgroundDuringPresentation = false
self.resultSearchController.searchBar.sizeToFit()
tableView.separatorColor = UIColor.brownColor()
self.tableView.tableHeaderView = self.resultSearchController.searchBar
self.tableView.reloadData()
}
override func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
let TotalLabel = UILabel()
TotalLabel.textAlignment = NSTextAlignment.Center
TotalLabel.text = "Hours: \(LogHours), Minutes: \(LogMinutes), Seconds: \(LogSeconds)" //Final Label
TotalLabel.textColor = UIColor.whiteColor()
TotalLabel.font = UIFont(name: "Papyrus", size: 20)
TotalLabel.backgroundColor = UIColor.blackColor()
self.view.addSubview(TotalLabel)
return TotalLabel;
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if (self.resultSearchController.active) {
return self.filteredDateStrings.count //Search
} else {
return self.swiftArray.count //Shows all objects
}
}
//TableView
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath)
cell.textLabel?.font = UIFont(name: "Papyrus", size: 17);
if (self.resultSearchController.active) {
cell.textLabel?.text = self.filteredDateStrings[indexPath.row]
return cell
} else {
cell.textLabel?.text = self.swiftArray[indexPath.row]
return cell
}
}
//Update tableview with seach
func updateSearchResultsForSearchController(searchController: UISearchController) {
self.filteredDateStrings.removeAll(keepCapacity: false)
let searchPredicate = NSPredicate(format: "SELF CONTAINS[c] %@", searchController.searchBar.text!)
let array = (self.swiftArray as NSArray).filteredArrayUsingPredicate(searchPredicate)
self.filteredDateStrings = array as! [String]
self.tableView.reloadData()
}
}