[英]iOS:How to dismiss other UIViewcontroller in current UIViewcontroller
I have three modal UIViewController
"A","B" and "C". 我有三个模式
UIViewController
“ A”,“ B”和“ C”。 "A" and "C" is Portrait
, "B" is "LandscapeRight" I click the button in "A" , "B" UIViewController
will present , If I click the button in "B" , "C" UIViewController
will present , When I click the button in "C" , I want to let "B" UIViewController
dismiss before "C" UIViewController
dismiss “ A”和“ C”是
Portrait
,“ B”是“ LandscapeRight”我单击“ A”中的按钮,“ B”将显示UIViewController
,如果我单击“ B”中的按钮,则将显示“ C” UIViewController
,当我点击“C”按钮,我想让“B” UIViewController
解雇之前的“C” UIViewController
解雇
I have try to put "B" UIViewController
to "C" and dismiss the "B" when click the button 我尝试将“ B”
UIViewController
为“ C”,并在单击按钮时关闭“ B”
in "B" 在“ B”中
let c = UIViewController()
c.b = self
self.presentViewController(c, animated: true, completion: nil)
then I click the button in "C" 然后点击“ C”中的按钮
b.dismissViewControllerAnimated(true, completion: { () -> Void in
self.dismissViewControllerAnimated(true, completion: { () -> Void in
})
})
When "C" is dismiss , "B" still display in the screen and did not disappear. 关闭“ C”时,“ B”仍显示在屏幕中,并且没有消失。
It is impossible to dismiss a view controller before the view controller present from it is disappeared. 在存在的视图控制器消失之前,不可能将其关闭。 As an alternative,you can try this way,add a bool variable in the B,and change the variable in the C.
或者,您可以尝试这种方式,在B中添加一个bool变量,然后在C中更改该变量。
code in B: B中的代码:
var shouldShow:Bool = true
override func viewWillAppear(animated: Bool) {
if !shouldShow{
self.dismissViewControllerAnimated(false) { () -> Void in
//
}
}
}
code in C: C中的代码:
@IBAction func clickButton(sender: AnyObject) {
vc!.shouldShow = false
self.dismissViewControllerAnimated(true, completion: { () -> Void in
//
})
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.