无法导航到UICollectionView Cell上的Next ViewController单击

时间:2017-03-29 02:54:17

标签: ios swift xcode uiviewcontroller uicollectionview

我有一个自定义UICollectionView Cell,其故事板设置如下:

enter image description here

自定义民意调查单元格只有一个imageView和一个标签。我希望基本上能够单击单元格,通过segue将数据传输到新的ViewController,然后在新的ViewController中填充数据(当前为空)。这是我收到的错误:

enter image description here

这是我的代码:

import UIKit
import FirebaseDatabase
import FirebaseDatabaseUI
import FirebaseStorageUI
import Material


private let reuseIdentifier = "PollCell"

class TrendingViewController: UICollectionViewController {

var ref: FIRDatabaseReference!
var dataSource: FUICollectionViewDataSource!
fileprivate var menuButton: IconButton!


override func viewDidLoad() {
    super.viewDidLoad()

    ref = FIRDatabase.database().reference()
    prepareMenuButton()
    print("TESTER")


    // Uncomment the following line to preserve selection between presentations
    // self.clearsSelectionOnViewWillAppear = false

    // Register cell classes

    self.dataSource = self.collectionView?.bind(to: self.ref.child("Polls")) { collectionView, indexPath, snap in
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! PollCell
        cell.pollQuestion.isUserInteractionEnabled = true;
        cell.imageView.isUserInteractionEnabled = true;
        /* populate cell */
        cell.pollQuestion.text = snap.childSnapshot(forPath: "question").value as! String?
        let urlPollImage = snap.childSnapshot(forPath: "image_URL").value as! String?
        cell.imageView.sd_setImage(with: URL(string: urlPollImage!), placeholderImage: UIImage(named: "Fan_Polls_Logo.png"))
        //Comment
        return cell
    }

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

override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    self.performSegue(withIdentifier: "toPoll", sender: nil)
}

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


extension TrendingViewController {
  fileprivate func prepareMenuButton() {
    menuButton = IconButton(image: Icon.cm.menu)
  }
 }

0 个答案:

没有答案
相关问题