ios - 所选图像未按顺序显示

标签 ios uitableview swift parse-platform

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

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

以下 block 是“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
}

我感谢任何帮助或见解!

最佳答案

事情就是这样:当您弹出 View Controller 时,新照片还没有完成上传。您可以等待照片完成上传(这不是一个很好的用户体验),或者您可以将对新保存对象的引用返回给弹出 View Controller ,然后弹出 View Controller 可以立即显示新照片而无需等待以完成上传。

关于ios - 所选图像未按顺序显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28794041/

相关文章:

ios - 如何检查或查找是否有我可以在 xcode 文档中使用的内置方法

ios - 未调用自定义 UITableViewCell didSelectRowAtIndexPath

ios - UIScrollView 在方向改变之前不滚动

ios - 将焦点设置到 tableCell 中的 UITextField

ios - 在 TableView 中按距离排序

ios - 当 View 位于 SwiftUI 中的 TabView 中时,NavigationView 标题不会出现

ios - 如何在 iOS 10 中更改特定栏按钮项目的色调颜色

ios - 如何在 UIButton 上触发不同的操作

ios - 无法构建项目 - libswiftAVFoundation.dylib : errSecInternalComponent error: Task failed with exit 1 signal 0

objective-c - 带有背景图片的 UITableView 样式