2017-09-26 7 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()를 사용할 필요가 있다고 생각? 이 문장에서'DetailVC()'대신'detailVC'를 사용해야한다고 생각합니다.'present (DetailVC(), animated : true, completion : nil)' – 3stud1ant3

+0

@ 3stud1ant3 나는 뭔가를 놓쳤다는 것을 알고 있습니다. 네, 문제였습니다. 고마워요! –

답변

1

당신은 detailVC에 대리자를 설정하는 다음 이유 대리자 메서드가 호출되고 있지 않은 새로운 인스턴스를 제시하는 .

그래서 나는 당신이 문 present(DetailVC(), animated: true, completion: nil)