ios - 传递 VC 数据无法正常工作

标签 ios swift parse-platform

当用户点击我的应用程序中的图像时,我希望将其发送到另一个 View Controller 以向他们提供更多帖子详细信息,但我不太清楚如何将该图像从一个 View Controller 传输到下一个!

下面的代码,如果他们点击图像,应该将它们发送到详细 View Controller - 这是在 else if 语句中完成的。

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
       if username != PFUser.currentUser()?.username {
            let profileVC: UserProfileViewController = segue.destinationViewController as! UserProfileViewController
            profileVC.usernameString = username

       } else if (segue.identifier == "toPostDetail") {
            var svc = segue.destinationViewController as! PostDetailsViewController

            svc.toPass = // Call/pass the image
      }
 }

为了检索我数据库中的所有帖子,我使用了以下代码,它运行得非常好,但我需要将 postImage 传输到下一个 View Controller 。

postsArray[indexPath.row]["image"].getDataInBackgroundWithBlock { (data, error) -> Void in
            if let downloadedImage = UIImage(data: data!) {
                postCellObj.postImage.image = downloadedImage
                postCellObj.postImage.layer.masksToBounds = true
                postCellObj.postImage.layer.cornerRadius = 5.0

            }
        }

那么我应该在 svc.toPass 中放入什么以便将图像发送到另一个 View Controller ?由于这是一系列帖子,我是否必须对 didSelectRowAtIndexPath 做一些事情,或者我做的是正确的事吗?我还使用 Parse.com 从我的数据库中获取信息。

最佳答案

你应该传递帖子而不是图片,所以它会是这样的

postsArray[indexPath.row]

如何获取 indexPath 由您决定。如果 segue 是由单元格选择触发的,那么您可以将 indexPath 存储在 didSelectRowAtIndexPath 中,或者您可以将 indexPath 作为 sender 当你触发 segue 时,或者你可以使用 indexPathForSelectedRow 如果它在 segue 过程中被保留。

关于ios - 传递 VC 数据无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35158337/

相关文章:

iphone - 为什么 UITableView 的滑动删除有时工作正常有时不工作?

iphone - 访问关系的计数会引发错误吗?

objective-c - 如果类没有前缀 `@objc` ,是否可以在 Objective-C 项目中使用用 Swift 编写的 pod?

ios - Swift - 转换 AutoreleasingUnsafeMutablePointer<AnyObject?> 值

ios - didRegisterForRemoteNotificationsWithDeviceToken 未执行 - 推送通知

ios - 单击 UIImageView 更改 ViewController

ios - ViewController 在使用 Firebase 的推送登录屏幕上出现 2-5 次(视频)

ios - 在 iOS 设备上显示使用 R 创建的 PDF 图的问题

ios - 如何在 addtarget 函数中发送附加参数?

ios - 'AppDelegate' 没有名为 'navController' 的成员