我在一个视图控制器上有一个UItable,从那个ViewController到另一个视图控制器是一种选择,它已被设置为一个主视图,以在滑动动作中显示三个笔尖。
视频
我按照此视频创建了滑动视图:https://www.youtube.com/watch?v=3jAlg5BnYUU
有点像这样:
ios - 将变量传递给加载的新 Nib 以进行滑动-LMLPHP
我可以使数据在两个视图控制器之间传递,但不能在任何笔尖上显示。
如何跨笔尖显示幻灯片,以显示在主视图(可折叠笔尖)控制器中定义的变量?
ViewController2.Swift

    let vc0 = vc0(nibName: "vc0", bundle: nil)
    let vc1 = vc1(nibName: "vc1", bundle: nil)
    let vc2 = vc2(nibName: "vc2", bundle: nil)

    // The above are the names of 3 other ViewControllers that were created with Nib Files. This code below, puts those nibs in a slide view.

    self.addChildViewController(vc0)
    self.scrollView.addSubview(vc0.view)
    vc0.didMoveToParentViewController(self)

    var frame1 = vc1.view.frame
    frame1.origin.x = self.view.frame.size.width
    vc1.view.frame = frame1
    self.addChildViewController(vc1)
    self.scrollView.addSubview(vc1.view)
    vc1.didMoveToParentViewController(self)

    var frame2 = vc2.view.frame
    frame2.origin.x = self.view.frame.size.width * 2
    vc2.view.frame = frame2
    self.addChildViewController(vc2)
    self.scrollView.addSubview(vc2.view)
    vc2.didMoveToParentViewController(self)



    self.scrollView.contentSize = CGSizeMake(self.view.frame.size.width * 3, self.view.frame.size.height - 66)
从第一个视图控制器到握住笔尖的视图控制器,我在prepareForSegue中传递变量。
如果您需要了解其他任何信息,请问:)
编辑1
第一个视图控制器称为viewcontroller,第二个(包含笔尖和上面的代码的一个)称为viewcontroller2:
ViewController1.Swift
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if "viewcontroller2Segue" == segue.identifier {

        let vc = segue.destinationViewController as! viewcontroller2;
        vc.passedID = clickedCell


    }
}
在viewcontroller2上,我有一个为其分配数据的变量:
var passedID = ""

最佳答案

此行let vc2 = vc2(nibName: "vc2", bundle: nil)实例化vc2的新实例,因此未设置其任何属性。从图中看来,您有一个容器视图控制器,该容器视图控制器具有类型为vc0,vc1,vc2的子视图控制器。我尚不清楚哪个类是segue.destinationViewController,也许是vc2,但是无论哪种方式,您都需要将segue.destinationViewController之间的数据传递到实例化的vc0,vc1和vc2。例如:

let vc0 = vc0(nibName: "vc0", bundle: nil)
let vc1 = vc1(nibName: "vc1", bundle: nil)
let vc2 = vc2(nibName: "vc2", bundle: nil)

vc0.neededID = self.passedID  //if vc0 needs passedID
vc1.neededID = self.passedID  //if vc1 needs passedID
vc2.neededID = self.passedID  //if vc2 needs passedID

关于ios - 将变量传递给加载的新 Nib 以进行滑动,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35180752/

10-12 14:49