2017-04-12 75 views
-2

我有一切正确的协议委托等设置。我唯一的问题是,我不能将CCC的委托设置为AAA。此代码在AAA.swift中:如何将模态子视图控制器的代表设置为父级?

override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
      if segue.identifier == "AAAtoBBBSegue"{ 

       let destination = segue.destination as! UINavigationController 
       let nextViewController = destination.viewControllers[0] as! CCC 

       nextViewController.delegate = self 

      } 
     } 

将CCC委派设置为AAA是我唯一的问题!这非常令人沮丧,因为我必须先设置它的委托,然后才能将任何数据从CCC传递到AAA。 http://i.imgur.com/AlOwue9.png

+0

那么,你为什么不能设置委托? –

+0

在您的屏幕截图中,CCC是* not * destination.viewControllers [0] ..您需要将代理设置为BBB并将其“传递给CCC – DonMag

+0

我刚拍了一张照片。我认为它们之间并不适用,因为它们之间有BBB。 –

回答

0

在你的设计,你试图设置在模态显示的导航控制器视图控制器的代表。

你想“让自己通过”来达到正确的风险投资。

所以:

  • 添加委托变量在BBB
  • 在用于赛格瑞准备从AAABBB,设置BBB.delegate = self(个体为AAA
  • BBB,当您继续使用CCC时,设置CCC.delegate = self.delegate(自这里是BBB,并self.delegateAAA