【问题标题】:Swift: Dismiss viewController 1 then present viewController 2Swift:关闭 viewController 1 然后呈现 viewController 2
【发布时间】:2016-11-17 09:59:04
【问题描述】:

我想关闭一个加载器视图控制器,然后呈现一个UIDocumentInteractionController。我找到了一个 Objective-c 解决方案,但我想要 Swift 3 的解决方案。

这是取自answer的objective-c代码:

// Does not break
[viewController1 dismissViewControllerAnimated:YES completion:^{
    [self presentViewController:viewController2 animated:YES completion:NULL];
}];

我在 Swift 3 中是这样翻译的:

 self.dismiss(animated: false, completion:{
                                self.docController = UIDocumentInteractionController(url: destinationUrl!)
                                self.docController!.presentOpenInMenu(from: CGRect.zero, in: self.view, animated: true)

})

它工作正常,但我想确定 Objective-c 中的 completion:^{ 表示 Swift 3 中的 completion:{

【问题讨论】:

  • 是的,它们是一样的

标签: ios objective-c swift swift3


【解决方案1】:

是的,你的假设是正确的。虽然您不需要在 Swift 3 中显式编写完成。

你也可以这样写。

self.dismiss(animated: false) { 
    self.docController = UIDocumentInteractionController(url: destinationUrl!)
    self.docController!.presentOpenInMenu(from: CGRect.zero, in: self.view, animated: true)
}

【讨论】:

    猜你喜欢
    • 2019-11-15
    • 1970-01-01
    • 1970-01-01
    • 2020-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-11
    • 1970-01-01
    相关资源
    最近更新 更多