-
Notifications
You must be signed in to change notification settings - Fork 0
/
BeerTypes.swift
98 lines (68 loc) · 2.73 KB
/
BeerTypes.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
97
//
// SecondViewController.swift
// Beer Manager
//
// Created by Connor Coughlin on 2/12/17.
// Copyright © 2017 Connor Coughlin. All rights reserved.
//
import Foundation
import UIKit
class BeerTypes: UIViewController, UISearchBarDelegate {
var categoryID = 1 // 30 for IPA for now
var beer_query = ""
var searched = false
// FB userID sent from login page
//var fbUserID:String!
@IBOutlet weak var searchBar: UISearchBar!
override func viewDidLoad() {
super.viewDidLoad()
needToRefreshMyList = true
searchBar.delegate = self
beer_query = ""
//Shift notes up code
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name: NSNotification.Name.UIKeyboardWillHide, object: nil)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
//Search bar functionality
func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
beer_query = searchBar.text!
searched = true
performSegue(withIdentifier: "segueBeerTypeConnect", sender: nil)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "segueBeerTypeConnect" {
var destination = segue.destination as! TableCellViewHolder
destination.beer_query = beer_query
destination.searched = searched
}
if segue.identifier == "showBookmarks" {
var destination = segue.destination as! bookmarks
destination.fromHomePage = true
}
if segue.identifier == "logoutSegue" {
var destination = segue.destination as! fbLogin
destination.fromLogout = true
}
}
func keyboardWillShow(notification: NSNotification) {
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
if self.view.frame.origin.y == 0{
self.view.frame.origin.y -= 100
}
}
}
func keyboardWillHide(notification: NSNotification) {
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
if self.view.frame.origin.y != 0{
self.view.frame.origin.y += 100
}
}
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
self.view.endEditing(true)
}
}