所选图像不按顺序显示

时间:2015-03-01 13:23:42

标签: ios uitableview swift parse-platform

我正在构建一个投票/ Instagram类型的应用程序,用户可以选择非用户制作的照片,该照片会被推送到时间轴中。

我已经建立了选择屏幕和按钮,以及时间轴。出于某种原因,我只能猜测它与保存PFObject(选择的照片)的年表有关,时间轴显示在当前所选照片之前选择的照片。

以下块是'SelectScreenVC'上的'选择'按钮:

@IBAction func selectNext(sender: UIButton) {
    let imageData = UIImagePNGRepresentation(lgImgURL.image)
    let imageFile = PFFile(name: "\(cName.text!)", data: imageData)

    var user = PFUser.currentUser()
    user["nextChosen"] = "\(cName.text!)"
    user["imageFile"] = imageFile

    var userNextPhoto = PFObject(className: "UserNextPhoto")

    userNextPhoto["username"] = PFUser.currentUser().username
    userNextPhoto["cName"] = "\(cName.text!)" as String
    userNextPhoto["imageFile"] = imageFile

    userNextPhoto.saveInBackgroundWithBlock { (success: Bool!, error: NSError!) -> Void in
        if error == nil {
            println("User \(PFUser.currentUser().username) chose: \(self.cName.text!)")
        } else {
            println(error)
        }
    }
    self.navigationController?.popToViewController(timeLineVC, animated: true)
}

这是TimeLineVC。我有创建时间轴数组的函数,我跳过了一些TableView方法,除了cellForRowAtIndexPath。

class TimeLineViewController: UITableViewController {

var timelineData:NSMutableArray = NSMutableArray()

override func viewDidLoad() {
    super.viewDidLoad()
    loadData()
}

func loadData() {
    timelineData.removeAllObjects()

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


    findTimelineData.findObjectsInBackgroundWithBlock { (objects: [AnyObject]!, error: NSError!) -> Void in
        if error == nil {
            for object in objects {
                self.timelineData.addObject(object)
            }
        } else {
            NSLog("Error: %@ %@", error, error.userInfo!)
        }

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

        self.tableView.reloadData()
    }

}

 override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell =     tableView.dequeueReusableCellWithIdentifier("timelineCell", forIndexPath:    indexPath) as TimelineTableViewCell
    let userNextPhoto:PFObject = self.timelineData.objectAtIndex(indexPath.row) as PFObject

    let nextPhoto:PFObject = self.timelineData.objectAtIndex(indexPath.row) as PFObject
    cell.usernameLabel.text = PFUser.currentUser().username
    cell.cName.text = (userNextPhoto["cName"] as String)
    return cell
}

我感谢任何帮助或见解!

1 个答案:

答案 0 :(得分:2)

正是这样:弹出视图控制器时,新照片尚未完成上传。您可以等待照片完成上传(这不是一个很好的用户体验),或者您可以将对新保存的对象的引用传回给弹出的视图控制器,然后可以立即显示新照片而无需等待上传完成。