forked from samyoungnyc/what-s-next
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VenueViewController.swift
104 lines (81 loc) · 3.75 KB
/
VenueViewController.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
98
99
100
101
102
103
104
//
// VenueCollectionViewController
// Whats Next
//
// Created by computer on 5/8/15.
// Copyright (c) 2015 computer. All rights reserved.
//
import UIKit
class VenueViewController: UICollectionViewController {
var venueItems: [Venue] = []
var searchController: UISearchController!
func fetchItems() {
let prepItems = Venue.query()
prepItems?.findObjectsInBackgroundWithBlock({ (objects:[AnyObject]?, error: NSError?) -> Void in
self.venueItems.removeAll(keepCapacity: false)
if (error == nil) {
for object in objects! {
self.venueItems.append(object as! Venue)
}
} else {
print("Error %@ %@", error, error!.userInfo)
}
self.collectionView?.reloadData()
})
}
override func viewDidLoad() {
super.viewDidLoad()
// MARK: NavBar Styling
let nav = self.navigationController?.navigationBar
nav?.barStyle = UIBarStyle.Black
let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 80, height: 45))
imageView.contentMode = .ScaleAspectFill
let image = UIImage(named: "navlogo")
imageView.image = image
navigationItem.titleView = imageView
// Fetch Venues for VenueCollectionView
fetchItems()
}
override func viewDidAppear(animated: Bool) {
// Defaults for segueing
let defaults = NSUserDefaults.standardUserDefaults()
if let _ = defaults.stringForKey("nextPushed") {
performSegueWithIdentifier("tab0", sender: self)
} else {
print("default reset to nil in FeedView")
}
}
override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 1
}
override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return venueItems.count
}
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexpath: NSIndexPath) -> CGSize {
let screenWidth = CGRectGetWidth(collectionView.bounds)
let cellWidth = screenWidth/3.0
return CGSize(width: cellWidth, height: cellWidth)
}
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout,
minimumLineSpacingForSectionAtIndex section: Int) -> CGFloat {
return 0
}
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("venueCell", forIndexPath: indexPath) as! VenueItemCell
let currentItem = venueItems[indexPath.row]
let imageView = PFImageView()
imageView.image = UIImage(named: "2.png")
imageView.file = currentItem.thumbImg
imageView.loadInBackground { (image: UIImage?, error: NSError?) -> Void in
cell.imageView!.image = image
cell.imageView.contentMode = .ScaleAspectFit
}
return cell
}
override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
let selectNavigationController = self.storyboard?.instantiateViewControllerWithIdentifier("selectNavController") as! UINavigationController
let selectVC = selectNavigationController.topViewController as! SelectViewController
selectVC.currentVenue = venueItems[indexPath.row]
presentViewController(selectNavigationController, animated: true, completion: nil)
}
}