0
我有一個父類A,它有兩個容器B和C以及兩個相應的uiviewcontrollers。我通過使用UISegmentContol切換兩個控制器。父類有一個對象「變量」,我想傳遞給UiViewControllers B和C.通過UISegmentControl將數據傳遞給childViewControllers
我的DouBt: 我該如何從父類共享一個對象到兩個子類? 我如何在父類中創建我的子類的引用?
class A: UIViewController {
@IBOutlet weak var segment: UISegmentedControl!
@IBOutlet var containerSearch: UIView!
@IBOutlet var containerAdvancedSearch: UIView!
var variables: Variables?
override func viewDidLoad() {
super.viewDidLoad()
let a = variables?.bankNameLong
print("from " + a! + "")
}
@IBAction func actionSwitchSegments(sender: AnyObject) {
if sender.selectedSegmentIndex == 0 {
UIView.animateWithDuration(0.5, animations: {
self.containerChangePassword.alpha = 1
self.containerAbout.alpha = 0
})
} else {
UIView.animateWithDuration(0.5, animations: {
self.containerChangePassword.alpha = 0
self.containerAbout.alpha = 1
})
}
}
if segue.identifier == "segSearch"{
let newViewController: vConSearch = segue.destinationViewController as! vConSearch
newViewController.Variables = self.Variables
}else if segue.identifier == "segAdvancedSearch"{
let newViewController: vConAdvancedSearch = segue.destinationViewController as! vConAdvancedSearch
newViewController.Variables = self.Variables
}
我試過使用segue,但它只適用於單個子控制器。 但通過做segue它不會創建一個新的實例,每次我點擊UiSegmentControl。
嘿@Darth Vader你能幫忙嗎? – Cloy
你在哪裏打電話performSegueWithIdentifier ?? – Ujjwal
從父類vConSettings – Cloy