2017-09-26 69 views
0

因此,我正在为我的应用程序进行一些海关过渡,我有一个问题将自实例传递给呈现类的过渡代理。我知道问题与实例有关,因为协议的方法没有执行。传递一个类的实例

我想我错过了一些东西,但我找不到。

的ViewController

class ViewController: UICollectionViewController, UICollectionViewDelegateFlowLayout { 

    let detailVC = DetailVC() 
    let animationController = AnimationController() 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     collectionView?.delegate = self 
     collectionView?.dataSource = self 

     detailVC.transitioningDelegate = self 

     collectionView?.register(ControllerCell.self, forCellWithReuseIdentifier: "klk") 
     collectionView?.isPagingEnabled = false 
     collectionView?.contentInset = UIEdgeInsets(top: 0, left: 80, bottom: 0, right: 10) 
     let layout = collectionView?.collectionViewLayout as? UICollectionViewFlowLayout 
     layout?.scrollDirection = .horizontal 

    } 

    override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 
     return 5 
    } 

    override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 
     let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "klk", for: indexPath) as! ControllerCell 
     return cell 
    } 

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { 
     return CGSize(width: view.frame.width * 0.6, height: view.frame.height * 0.5) 
    } 

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat { 
     return 100 
    } 


    override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { 
     let cell = collectionView.cellForItem(at: indexPath) 
     animationController.originFrame = cell?.frame 
     present(DetailVC(), animated: true, completion: nil) 
    } 

} 

extension ViewController: UIViewControllerTransitioningDelegate { 

    func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? { 
     return animationController 
    } 
} 

DetailVC

class DetailVC: UIViewController { 

    var cellFrame: CGRect? 

    let label: UILabel = { 
     let lbl = UILabel() 
     lbl.textColor = .white 
     lbl.text = "Quitar" 
     lbl.frame = CGRect(x: 10, y: 10, width: 100, height: 100) 
     lbl.isUserInteractionEnabled = true 
     return lbl 
    }() 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     view.addSubview(label) 
     view.backgroundColor = .blue 
     label.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(dismissing))) 
    } 

    func dismissing() { 
     dismiss(animated: true, completion: nil) 
    } 


} 
+0

您使用的故事板使用detailVC代替DetailVC()?我认为你需要在这个语句present(DetailVC(),animated:true,completion:nil)中使用'detailVC'而不是'DetailVC()'' – 3stud1ant3

+0

@ 3stud1ant3我知道我错过了一些东西。是的,这是问题,谢谢! –

回答

1

要设置在detailVC委托,然后你提出一个新的实例,这就是为什么你的委托方法不会被调用。

所以,我认为你需要在此声明present(DetailVC(), animated: true, completion: nil)

相关问题