EventsViewController.swift 2.36 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//
//  EventsViewController.swift
//  Amiv
//
//  Created by Domenic Wüthrich on 20.09.18.
//  Copyright © 2018 Amiv an der ETH. All rights reserved.
//

import Foundation
import UIKit

public class EventsViewController: UITableViewController {
    
    // MARK: - Variables
    
domenicw's avatar
domenicw committed
16
17
    public var delegate: EventsViewControllerDelegate?
    
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
    // MARK: - Initializers
    
    public init() {
        super.init(style: .plain)
        self.title = "Events"
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - View Setup
    
    public override func viewDidLoad() {
        super.viewDidLoad()
        
domenicw's avatar
domenicw committed
34
35
36
37
38
39
40
        let refreshControl = UIRefreshControl()
        refreshControl.addTarget(self, action: #selector(self.refreshData), for: .primaryActionTriggered)
        self.tableView.refreshControl = refreshControl
    }
    
    public override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
41
42
43
44
45
        
        self.navigationController?.navigationBar.prefersLargeTitles = true
        self.navigationItem.largeTitleDisplayMode = .automatic
    }
    
domenicw's avatar
domenicw committed
46
47
48
49
50
51
    public override func viewDidDisappear(_ animated: Bool) {
        super.viewDidDisappear(animated)
        
        self.refreshControl?.endRefreshing()
    }
    
52
53
    // MARK: - View Interaction
    
domenicw's avatar
domenicw committed
54
55
56
57
    @objc private func refreshData() {
        self.delegate?.refreshData()
    }
    
58
59
60
61
62
63
64
65
66
67
68
}

// MARK: - Table View Data Source

extension EventsViewController {
    
    public override func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    
    public override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
domenicw's avatar
domenicw committed
69
        return 1
70
71
72
73
74
75
76
77
78
79
80
    }
    
    public override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        return UITableViewCell()
    }
    
    public override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
        return ""
    }
    
}
domenicw's avatar
domenicw committed
81
82
83
84
85
86
87
88
89
90
91

// MARK: - Table View Delegate

extension EventsViewController {
    
    public override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        self.delegate?.didSelectEvent(section: indexPath.section, index: indexPath.row)
        tableView.deselectRow(at: indexPath, animated: true)
    }
    
}