I am trying to add parse data for an "Announcements" page on my app. I have set up the pages ViewController, Added the TableView, and followed the steps to get it to accurately print the correct amount of rows. The issue is the text itself. I am trying to connect it to a UILabel for the Header but its not working. Any help is appreciated.
import UIKit
import Parse
import Bolts
class ViewController: UIViewController, UITableViewDelegate {
@IBOutlet var tableView: UITableView!
var Header = [String]()
let reuseIdentifier = "ContentCell"
private let cellHeight: CGFloat = 210
private let cellSpacing: CGFloat = 20
@IBOutlet var barButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
let navBar = self.navigationController!.navigationBar
navBar.barTintColor = UIColor(red: 6.0 / 255.0, green: 100.0 / 255.0, blue: 255.0 / 255.0, alpha: 1)
navBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()]
var query = PFQuery(className: "Announcements")
query.orderByDescending("createdAt")
query.findObjectsInBackgroundWithBlock {
(posts:[PFObject]?, error: NSError?) -> Void in
if error == nil {
//success fetching announcements
for alert in posts! {
print(alert)
self.Header.append(alert["Header"] as! String)
}
/***Reload The Table***/
print(self.Header.count)
self.tableView.reloadData()
} else {
print(error)
}
}
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
return Header.count
//turns announcements into rows
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
let singleCell: AnnouncementCellTableViewCell = tableView.dequeueReusableCellWithIdentifier("AnnouncementBlock") as! AnnouncementCellTableViewCell
singleCell.HeaderText.text = Header[indexPath.row]
return singleCell
}