我在视图控制器上有一个UItable,从那个ViewController是一个segue到另一个视图控制器,它已经被设置为一种主人,可以在滑动动作中显示三个笔尖。
我按照此视频制作了幻灯片视图:https://www.youtube.com/watch?v=3jAlg5BnYUU
有点像这样:
我可以在两个视图控制器之间传递数据,但是我无法在任何一个nib上显示它。
如何获取笔尖上的幻灯片以显示在主视图中定义的变量(一个包含nibs的控制器)控制器?
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)
从第一个视图控制器到持有nib的那个我在prepareForSegue中传递变量。
如果您还需要了解其他信息,请询问:)
第一个视图控制器被称为viewcontroller,第二个视图控制器(包含上面的代码和上面的代码)被称为viewcontroller2:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if "viewcontroller2Segue" == segue.identifier {
let vc = segue.destinationViewController as! viewcontroller2;
vc.passedID = clickedCell
}
}
在viewcontroller2上,我有一个变量,它被分配了数据:
var passedID = ""
答案 0 :(得分:1)
此行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