【发布时间】:2016-03-29 14:02:41
【问题描述】:
我有一个父类 A,它有两个容器 B 和 C,分别有两个 uiviewcontroller。我正在使用 UISegmentContol 切换两个控制器。父类有一个对象“变量”,我想将它传递给 UiViewControllers B 和 C。
我的疑问: 如何将父类中的对象共享给两个子类? 如何在父类中创建子类的引用?
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,你能帮忙吗?
-
从哪里调用 performSegueWithIdentifier??
-
来自父类 vConSettings
-
我没有看到代码。你能检查一下你的prepareforsegue是否被调用。谢谢
-
嘿@Ujjwal .....我已经更新了代码..你能看看..
标签: ios uiviewcontroller swift2 parameter-passing uisegmentedcontrol