-
Notifications
You must be signed in to change notification settings - Fork 0
/
TrendingChallengeTableViewController.swift
87 lines (59 loc) · 2.55 KB
/
TrendingChallengeTableViewController.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
//
// TrendingChallengeTableViewController.swift
// PiqChallenge
//
// Created by Darryl Nunn on 2/22/16.
// Copyright © 2016 Parse. All rights reserved.
//
import UIKit
import Parse
var pressedChallenge: String?
class TrendingChallengeTableViewController: UITableViewController {
var images = [PFFile]()
var usernames = [String]()
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.hidesBackButton = true
let query = PFQuery(className: "Post")
query.whereKey("imageComment", equalTo: pressedChallenge!)
query.orderByDescending("createdAt")
query.findObjectsInBackgroundWithBlock { (object, error) -> Void in
self.usernames.removeAll(keepCapacity: true)
self.images.removeAll(keepCapacity: true)
if let object = object {
for images in object {
self.images.append(images["imageFile"] as! PFFile)
self.usernames.append(images["username"] as! String)
self.tableView.reloadData()
}
}
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return usernames.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let trendCell = tableView.dequeueReusableCellWithIdentifier("trendingCell", forIndexPath: indexPath) as! TrendingChallengeTableViewCell
if images.count > 0 {
trendCell.postComment.text = "\(usernames[indexPath.row]) completed the \(pressedChallenge!) challenge!"
images[indexPath.row].getDataInBackgroundWithBlock { (data, error) -> Void in
if let downloadedImage = UIImage(data: data!) {
trendCell.postImage.image = downloadedImage
} else {
print(error)
}
}
}
return trendCell
}
}