Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/103.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 快速自动重新加载数据_Ios_Xcode_Swift - Fatal编程技术网

Ios 快速自动重新加载数据

Ios 快速自动重新加载数据,ios,xcode,swift,Ios,Xcode,Swift,嗨,我正试图找出如何使它,使我的所有数据为我的时间表可以重新加载自己。这是我当前用于整个TimeLineViewController的代码 import UIKit import CoreData class TimelineTableViewController: UITableViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate, UITextFieldDelegate, UIAler

嗨,我正试图找出如何使它,使我的所有数据为我的时间表可以重新加载自己。这是我当前用于整个TimeLineViewController的代码

import UIKit
import CoreData

class TimelineTableViewController: UITableViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate, UITextFieldDelegate, UIAlertViewDelegate {

var timelineData:NSMutableArray! = NSMutableArray()

override init(style: UITableViewStyle) {
    super.init(style: style)
    // Custom initialization
}
@IBAction func reportButton(sender: AnyObject) {
    performSegueWithIdentifier("reportSegue", sender: self)
}

@IBAction func composeStatus(sender: AnyObject) {
    performSegueWithIdentifier("composeSegue", sender:self)
}

@IBAction func logout(sender: AnyObject) {
    PFUser.logOut()
    var currentUser = PFUser.currentUser() // this will now be nil
        performSegueWithIdentifier("logoutSegue", sender:self)
    }

required init(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
}

func loadData(){

    timelineData.removeAllObjects()

    var findTimelineData:PFQuery = PFQuery(className: "woofs")

    findTimelineData.findObjectsInBackgroundWithBlock{
        (objects:[AnyObject]!, error:NSError!)->Void in
        if error == nil{
            for object in objects{
                let woofs:PFObject = object as PFObject
                self.timelineData.addObject(woofs)
            }

            let array:NSArray = self.timelineData.reverseObjectEnumerator().allObjects
            self.timelineData = NSMutableArray(array: array)

            self.tableView.reloadData()
        }
    }
}

override func viewDidAppear(animated: Bool) {
    self.loadData()
}

func refresh(sender:AnyObject)
{
    // Updating your data here...
    self.tableView.reloadData()
    self.refreshControl?.endRefreshing()
}

override func viewDidLoad() {
    super.viewDidLoad()

    var statusBarHidden: Bool

    /*var newFeatureAlert:UIAlertController = UIAlertController(title: "Attention", message: "New feature added. You can now Report content that you find offensive. Just tap on Report to get the instructions on how to.", preferredStyle: UIAlertControllerStyle.Alert)

    newFeatureAlert.addAction(UIAlertAction(title: "AWESOME!", style: UIAlertActionStyle.Default, handler: nil))
    self.presentViewController(newFeatureAlert, animated: true, completion: nil)*/

    self.refreshControl?.addTarget(self, action: "refresh:", forControlEvents: UIControlEvents.ValueChanged)

    UITextView.appearance().tintColor = UIColor.blackColor().colorWithAlphaComponent(1.0)
    UITextView.appearance().backgroundColor = UIColor.clearColor().colorWithAlphaComponent(0.4)
    self.tableView.backgroundView = UIImageView(image: UIImage(named: "hdwallpaper"))
    }

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    // #warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 1
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    // #warning Incomplete method implementation.
    // Return the number of rows in the section.
    return timelineData.count
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell:PAHTableViewCell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as PAHTableViewCell

    cell.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.3)

    let woofers:PFObject = self.timelineData.objectAtIndex(indexPath.row) as PFObject

    cell.pahTextView.alpha = 0

    cell.timestampLabel.alpha = 0

    cell.usernameLabel.alpha = 0

    cell.pahTextView.text = woofers.objectForKey("content") as String

    var dataFormatter:NSDateFormatter = NSDateFormatter()

    dataFormatter.dateFormat = "dd-MM-yyyy HH:mm"

    cell.timestampLabel.text = dataFormatter.stringFromDate(woofers.createdAt)

    var findwoofers:PFQuery = PFUser.query()

    findwoofers.whereKey("objectId", equalTo: woofers.objectForKey("woofers").objectId)

    findwoofers.findObjectsInBackgroundWithBlock{

        (objects:[AnyObject]!, error:NSError!)->Void in if error == nil{

            if let user:PFUser = (objects as NSArray).lastObject as? PFUser{

                cell.usernameLabel.text = user.username
                cell.timestampLabel.alpha = 0
                cell.profileImageView.alpha = 0
                cell.pahTextView.alpha = 0

                if let profileImage = user["profileImage"] as? PFFile{

                    profileImage.getDataInBackgroundWithBlock {
                    (imageData: NSData!, error: NSError!) -> Void in
                    if error == nil {
                        let image = UIImage(data:imageData)
                        cell.profileImageView.image = image
                    }else{
                        let image = UIImage(named: "BLUEPAW")
                        }
                    }
                }
            }
        }
        UIView.animateWithDuration(1.0, animations:{
            cell.profileImageView.alpha = 1
            cell.usernameLabel.alpha = 2
            cell.timestampLabel.alpha = 4
            cell.pahTextView.alpha = 3
        })
    }
    return cell
}
让我知道我需要改变什么才能让这一切顺利进行。谢谢。

查看本教程