我有一个包含多个视图控制器的滚动视图。在那些视图控制器上,我有开关。当开关是"开"所有其他开关都关闭。这一切都是通过viewDidLoad
完成的。
我无法让这个工作,但我已经尝试将代码用于我想要在viewWillAppear
中尝试做的切换。虽然这两种方法似乎只在运行时调用。
我的另一个想法是以某种方式"重置"来自其中一个子视图的滚动视图
这就是我所拥有的:
class ViewController: UIViewController {
@IBOutlet weak var scrollView: UIScrollView!
override func viewDidLoad() {
super.viewDidLoad()
let vc0 = ViewController0(nibName: "ViewController0", bundle: nil)
self.addChildViewController(vc0)
self.scrollView.addSubview(vc0.view)
vc0.didMoveToParentViewController(self)
let vc1 = ViewController1(nibName: "ViewController1", bundle:nil)
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)
let vc2 = ViewController2(nibName: "ViewController2", bundle:nil)
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)
let vc3 = ViewController2(nibName: "ViewController3", bundle:nil)
var frame3 = vc3.view.frame
frame3.origin.x = self.view.frame.size.width * 3
vc3.view.frame = frame3
self.addChildViewController(vc3)
self.scrollView.addSubview(vc3.view)
vc3.didMoveToParentViewController(self)
self.scrollView.contentSize = CGSizeMake(self.view.frame.size.width * 4, self.view.frame.size.height - 66);
}
}
^用于scrollUI创建者类
import UIKit
class ViewController0: UIViewController {
@IBOutlet weak var onoff: UISwitch!
override func viewDidLoad() {
super.viewDidLoad()
onoff.on = false
}
@IBAction func used(sender: AnyObject) {
let parent = self.view.superview
parent?.setNeedsDisplay()
}
}
^这是子类之一
这个子类有一个开关,当切换时,它应该"重置"滚动视图,以便再次调用所有子视图viewDidLoad
...
这不起作用....有没有解决方案?
BTW抱歉代码块格式不正确。