Swift
I'm trying to make it so when you pull to refresh on the tableview it updates the tableview with the data that is stored on Parse.com
I've researched this and it seems I need to use loadObjects()
When I place this in it says: "Use of unresolved identifier 'loadObjects'
Not sure if this is what I need or not..
Here is my ViewController.swift
import UIKit
import Parse
import Bolts
import ParseUI
class EventsViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
var timer: NSTimer!
var isAnimating = false
var currentColorIndex = 0
var currentLabelIndex = 0
var customView: UIView!
var labelsArray: Array<UILabel> = []
var refreshControl: UIRefreshControl!
var testArray = [String]()
var subArray = [String]()
@IBOutlet weak var tableview: UITableView!
@IBOutlet weak var webView: UIWebView!
override func viewDidLoad() {
    super.viewDidLoad()
    tableview.delegate = self
    tableview.dataSource = self
    refreshControl = UIRefreshControl()
    tableview.addSubview(refreshControl)
    loadCustomRefreshContents()
    //refreshControl colors
    refreshControl.backgroundColor = UIColor.clearColor() //color of background
    refreshControl.tintColor = UIColor.clearColor() //color of indicator
    let query = PFQuery(className: "events")
    let runkey = query.orderByDescending("eventTitle")
    runkey.findObjectsInBackgroundWithBlock {
        (objects: [PFObject]?, error:NSError?) -> Void in
        if error == nil {
            if let objects = objects as [PFObject]! {
                for object in objects {
                    let load = object.objectForKey("eventTitle") as! String
                    self.testArray.append(load)
                    let subload = object.objectForKey("date") as! String
                    self.subArray.append(subload)
                    print(self.testArray)
                }
            }
        } else {
            print("error:\(error!) \(error!.userInfo)")
        }
    }
    sleep(3)
    do_table_refresh()
    loadViewIfNeeded()
    loadObjects()
    /*let url = NSURL(string: "https://m.facebook.com/CathedralCityMunicipal")
    let task = NSURLSession.sharedSession().dataTaskWithURL(url!) {
        (data, response, error) in
        if error == nil {
            let urlContent = NSString(data: data!, encoding: NSUTF8StringEncoding)
            print(urlContent)
            dispatch_async(dispatch_get_main_queue()) {
            self.webView.loadHTMLString(urlContent! as String, baseURL: nil)
            }
        }
    }
    task.resume()*/
    // Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}
func do_table_refresh() {
    dispatch_async(dispatch_get_main_queue()) {
        self.tableview.reloadData()
        return
    }
}
func tableView(tableView:UITableView!, numberOfRowsInSection section:Int) -> Int {
    return testArray.count
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return 1
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("eventcell", forIndexPath: indexPath) as! EventTableViewCell
    cell.title.text = self.testArray[indexPath.row]
    cell.subTitle.text = self.subArray[indexPath.row]
    return cell
}
//refreshes tableview; starts refresh
func loadCustomRefreshContents() {
    let refreshContents = NSBundle.mainBundle().loadNibNamed("RefreshControl", owner: self, options: nil)
    customView = refreshContents[0] as! UIView
    customView.frame = refreshControl.bounds
    for var i=0; i<customView.subviews.count; ++i {
        labelsArray.append(customView.viewWithTag(i + 1) as! UILabel)
    }
    refreshControl.addSubview(customView)
    do_table_refresh()
}
//stops refresh
func scrollViewDidEndDecelerating(scrollView: UIScrollView) {
    do_table_refresh()
    if refreshControl.refreshing {
        if !isAnimating {
            doSomething()
            animateRefreshStep1()
            self.do_table_refresh()
        }
    }
}
//cycles through colors
func getNextColor() -> UIColor {
    var colorsArray: Array<UIColor> = [UIColor.magentaColor(), UIColor.brownColor(), UIColor.yellowColor(), UIColor.redColor(), UIColor.greenColor(), UIColor.blueColor(), UIColor.orangeColor()]
    if currentColorIndex == colorsArray.count {
        currentColorIndex = 0
    }
    let returnColor = colorsArray[currentColorIndex]
    ++currentColorIndex
    return returnColor
}
func doSomething() {
    timer = NSTimer.scheduledTimerWithTimeInterval(4.0, target: self, selector: "endOfWork", userInfo: nil, repeats: true)
    self.do_table_refresh()
}
func endOfWork() {
    refreshControl.endRefreshing()
    self.do_table_refresh()
    timer.invalidate()
    timer = nil
}
//first part of animation
func animateRefreshStep1() {
    isAnimating = true
    UIView.animateWithDuration(0.1, delay: 0.0, options: UIViewAnimationOptions.CurveLinear, animations: { () -> Void in
        self.labelsArray[self.currentLabelIndex].transform = CGAffineTransformMakeRotation(CGFloat(M_PI_4))
        self.labelsArray[self.currentLabelIndex].textColor = self.getNextColor()
        }, completion: { (finished) -> Void in
            UIView.animateWithDuration(0.05, delay: 0.0, options: UIViewAnimationOptions.CurveLinear, animations: { () -> Void in
                self.labelsArray[self.currentLabelIndex].transform = CGAffineTransformIdentity
                self.labelsArray[self.currentLabelIndex].textColor = UIColor.blackColor()
                }, completion: { (finished) -> Void in
                    ++self.currentLabelIndex
                    if self.currentLabelIndex < self.labelsArray.count {
                        self.animateRefreshStep1()
                    }
                    else {
                        self.animateRefreshStep2()
                    }
            })
    })
}
//second part of animation
func animateRefreshStep2() {
    UIView.animateWithDuration(0.35, delay: 0.0, options: UIViewAnimationOptions.CurveLinear, animations: { () -> Void in
        self.labelsArray[0].transform = CGAffineTransformMakeScale(1.5, 1.5)
        self.labelsArray[1].transform = CGAffineTransformMakeScale(1.5, 1.5)
        self.labelsArray[2].transform = CGAffineTransformMakeScale(1.5, 1.5)
        self.labelsArray[3].transform = CGAffineTransformMakeScale(1.5, 1.5)
        self.labelsArray[4].transform = CGAffineTransformMakeScale(1.5, 1.5)
        self.labelsArray[5].transform = CGAffineTransformMakeScale(1.5, 1.5)
        self.labelsArray[6].transform = CGAffineTransformMakeScale(1.5, 1.5)
        self.labelsArray[7].transform = CGAffineTransformMakeScale(1.5, 1.5)
        self.labelsArray[8].transform = CGAffineTransformMakeScale(1.5, 1.5)
        self.labelsArray[9].transform = CGAffineTransformMakeScale(1.5, 1.5)
        }, completion: { (finished) -> Void in
            UIView.animateWithDuration(0.25, delay: 0.0, options: UIViewAnimationOptions.CurveLinear, animations: { () -> Void in
                self.labelsArray[0].transform = CGAffineTransformIdentity
                self.labelsArray[1].transform = CGAffineTransformIdentity
                self.labelsArray[2].transform = CGAffineTransformIdentity
                self.labelsArray[3].transform = CGAffineTransformIdentity
                self.labelsArray[4].transform = CGAffineTransformIdentity
                self.labelsArray[5].transform = CGAffineTransformIdentity
                self.labelsArray[6].transform = CGAffineTransformIdentity
                self.labelsArray[7].transform = CGAffineTransformIdentity
                self.labelsArray[8].transform = CGAffineTransformIdentity
                self.labelsArray[9].transform = CGAffineTransformIdentity
                }, completion: { (finished) -> Void in
                    if self.refreshControl.refreshing {
                        self.currentLabelIndex = 0
                        self.animateRefreshStep1()
                    }
                    else {
                        self.isAnimating = false
                        self.currentLabelIndex = 0
                        for var i=0; i<self.labelsArray.count; ++i {
                            self.labelsArray[i].textColor = UIColor.blackColor()
                            self.labelsArray[i].transform = CGAffineTransformIdentity
                        }
                    }
            })
    })
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    // Get the new view controller using segue.destinationViewController.
    // Pass the selected object to the new view controller.
}
*/
}
I have tried letting the do_table_refresh() function run after the refresh is over, but the tableview does not update. I have also tried using self.tableview.reloadData() but also does not work.
I'm not sure what I am doing wrong, any help is greatly appreciated!
Feel free to ask me for any additional information!
Thank you for your time!
 
    