iOS解除了一系列ViewControllers

时间:2016-05-20 14:17:00

标签: ios uiviewcontroller segue uistoryboard

我对iOS中的以下行为感到有点困惑(目标是在Xcode 7.3.1中使用iOS 9.3的iPad)。我有以下层次结构:

Storyboard1
|
| initial
|
A (UIViewController)
|
| UIStoryboardSegue Present Modally
|
B (UINavigationController)
|
| root
|
C (UIViewController)
|
| presentViewController
|
Storyboard2
|
| initial
|
D (UIViewController)
|
| UIStoryboardSegue Present Modally
|
E (UIViewController) here

E完成后,我想回到A,因此我考虑在self.navigationController?.dismissViewControllerAnimated(true, nil)中使用C,我在E打电话给C保持对C的弱引用,但这会让我回到A而不是A。如果我想回到 $s3->putObjectAcl([ 'Bucket' => 'myBucketName', 'Key' => 'myFileName', 'ACL' => 'private' ]); ,我必须两次发出相同的解雇命令。我错过了什么?

2 个答案:

答案 0 :(得分:1)

Wolfy,

只需致电,

UIApplication.sharedApplication().keyWindow?.rootViewController?.dismissViewControllerAnimated(true, completion: nil)

工作原理

UIApplication.sharedApplication().keyWindow?.rootViewController will return `A (UIViewController)` 

因为ViewController以模态方式呈现B (UINavigationController)并且所有其他viewControllers都被加载到此导航堆栈中,解雇B (UINavigationController)将为您卸载所有viewControllers:)

快乐编码:)

答案 1 :(得分:1)

要解除多个模态,您可以这样做:

A.dismissViewControllerAnimated(true,nil)
相关问题