Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.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 UICollectionView到DetailView Swift,使用parse_Ios_Swift_Parse Platform_Uicollectionview_Uicollectionviewcell - Fatal编程技术网

Ios UICollectionView到DetailView Swift,使用parse

Ios UICollectionView到DetailView Swift,使用parse,ios,swift,parse-platform,uicollectionview,uicollectionviewcell,Ios,Swift,Parse Platform,Uicollectionview,Uicollectionviewcell,我有一个UICollectionview,它从解析中获取图像 我现在尝试推送到细节视图,然后在UICollectionView中推送图像 有人知道怎么做吗 这是我的密码: 视图控制器: import UIKit import Parse class ViewController: UIViewController, UICollectionViewDelegateFlowLayout, UICollectionViewDataSource { @I

我有一个UICollectionview,它从解析中获取图像

我现在尝试推送到细节视图,然后在UICollectionView中推送图像

有人知道怎么做吗

这是我的密码:

视图控制器:

       import UIKit
    import Parse
    class ViewController: UIViewController, UICollectionViewDelegateFlowLayout, UICollectionViewDataSource {

        @IBOutlet var collectionView: UICollectionView?
        var imageFilesArray:NSArray = NSArray()
        var refreshControl: UIRefreshControl!
      //  var isAscending = true
        override func viewDidLoad() {
            super.viewDidLoad()

            self.refreshControl = UIRefreshControl()
            self.refreshControl.attributedTitle = NSAttributedString(string: "Pull to refresh")
            self.refreshControl.addTarget(self, action: Selector("imageRefresh"), forControlEvents: UIControlEvents.ValueChanged)
            self.refreshControl.tintColor = UIColor.whiteColor()
            self.collectionView?.addSubview(refreshControl)
            // Do any additional setup after loading the view, typically from a nib.
            //let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
            //layout.sectionInset = UIEdgeInsets(top: 20, left: 10, bottom: 20, right: 10)
            //layout.itemSize = CGSize(width: 150 , height: 150)
        //    collectionView = UICollectionView(frame: self.view.frame, collectionViewLayout: layout)
            collectionView!.dataSource = self
            collectionView!.delegate = self
            collectionView!.registerClass(CollectionViewCell.self, forCellWithReuseIdentifier: "imageCell")
            collectionView?.alwaysBounceVertical = true
            //collectionView!.backgroundColor = UIColor.whiteColor()
            self.view.addSubview(collectionView!)
            parseQuery()



        }
func parseQuery() {
        //query
        var query = PFQuery(className: "photo")
        query.orderByDescending("createdAt")
        query.findObjectsInBackgroundWithBlock{
            (objects: [AnyObject]!, error: NSError!) -> Void in
            if error == nil {

                self.imageFilesArray = objects
                //println(self.imageFilesArray)
            }

            self.collectionView?.reloadData()
        }
    }


    func imageRefresh() {
        parseQuery()
        self.refreshControl.endRefreshing()
    }

    func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
        return 1
    }

    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        println(self.imageFilesArray.count)
        return self.imageFilesArray.count
    }

    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier("imageCell", forIndexPath: indexPath) as CollectionViewCell
        cell.backgroundColor = UIColor.blackColor()
         let imageObject = self.imageFilesArray.objectAtIndex(indexPath.row) as PFObject
         let imageFile  = imageObject.objectForKey("imageFile") as PFFile
        imageFile.getDataInBackgroundWithBlock{
            (data: NSData!, error: NSError!) -> Void in
            if error == nil {
                cell.imageView.image = UIImage(data: data)
            }
        }

        return cell
    }

    func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}
import UIKit
import Parse
class photoDetailViewController: UIViewController {
    @IBOutlet var detailImageView: UIImageView!

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


    /*
    // 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.
    }
    */

}
collectionviewcell:

import UIKit

class CollectionViewCell: UICollectionViewCell {
    @IBOutlet var imageView: UIImageView!
    required init(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }



    override init(frame: CGRect) {
        super.init(frame: frame)

        imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: frame.size.width, height: frame.size.height))
        imageView.contentMode = UIViewContentMode.ScaleToFill
        contentView.addSubview(imageView)


    }

}
Detailviewcontroller:

       import UIKit
    import Parse
    class ViewController: UIViewController, UICollectionViewDelegateFlowLayout, UICollectionViewDataSource {

        @IBOutlet var collectionView: UICollectionView?
        var imageFilesArray:NSArray = NSArray()
        var refreshControl: UIRefreshControl!
      //  var isAscending = true
        override func viewDidLoad() {
            super.viewDidLoad()

            self.refreshControl = UIRefreshControl()
            self.refreshControl.attributedTitle = NSAttributedString(string: "Pull to refresh")
            self.refreshControl.addTarget(self, action: Selector("imageRefresh"), forControlEvents: UIControlEvents.ValueChanged)
            self.refreshControl.tintColor = UIColor.whiteColor()
            self.collectionView?.addSubview(refreshControl)
            // Do any additional setup after loading the view, typically from a nib.
            //let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
            //layout.sectionInset = UIEdgeInsets(top: 20, left: 10, bottom: 20, right: 10)
            //layout.itemSize = CGSize(width: 150 , height: 150)
        //    collectionView = UICollectionView(frame: self.view.frame, collectionViewLayout: layout)
            collectionView!.dataSource = self
            collectionView!.delegate = self
            collectionView!.registerClass(CollectionViewCell.self, forCellWithReuseIdentifier: "imageCell")
            collectionView?.alwaysBounceVertical = true
            //collectionView!.backgroundColor = UIColor.whiteColor()
            self.view.addSubview(collectionView!)
            parseQuery()



        }
func parseQuery() {
        //query
        var query = PFQuery(className: "photo")
        query.orderByDescending("createdAt")
        query.findObjectsInBackgroundWithBlock{
            (objects: [AnyObject]!, error: NSError!) -> Void in
            if error == nil {

                self.imageFilesArray = objects
                //println(self.imageFilesArray)
            }

            self.collectionView?.reloadData()
        }
    }


    func imageRefresh() {
        parseQuery()
        self.refreshControl.endRefreshing()
    }

    func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
        return 1
    }

    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        println(self.imageFilesArray.count)
        return self.imageFilesArray.count
    }

    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier("imageCell", forIndexPath: indexPath) as CollectionViewCell
        cell.backgroundColor = UIColor.blackColor()
         let imageObject = self.imageFilesArray.objectAtIndex(indexPath.row) as PFObject
         let imageFile  = imageObject.objectForKey("imageFile") as PFFile
        imageFile.getDataInBackgroundWithBlock{
            (data: NSData!, error: NSError!) -> Void in
            if error == nil {
                cell.imageView.image = UIImage(data: data)
            }
        }

        return cell
    }

    func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}
import UIKit
import Parse
class photoDetailViewController: UIViewController {
    @IBOutlet var detailImageView: UIImageView!

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


    /*
    // 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.
    }
    */

}
我希望有人能在如何编写代码以推送到细节视图,并显示按下的相同图像方面提供帮助

--
Olepeter

更新您的didSelectItemAtIndexPath方法

func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath)
{
    var detailsViewController: DetailsViewController = DetailsViewController(nibName:"DetailsViewController",bundle:nil)
    self.presentViewController(detailsViewController, animated: true) { () -> Void in

    }
}

注意:在写下您自己的详细信息ViewController的名称以代替DetailsViewController。写下你自己的名字,谢谢!你知道如何将单元格中的图像推送到细节视图吗?