【问题标题】:Dismiss modal from a view in a tab bar view从标签栏视图中的视图中关闭模式
【发布时间】:2018-03-07 19:52:59
【问题描述】:

如何关闭从标签栏视图中的视图打开的模式视图并停留在该视图上?

登录后我有一个标签栏视图,标签视图上有两个视图(客户端和配置文件)。

在客户上,我有一个客户列表,我可以打开另一个显示发票的视图。

点击发票,它会显示特定发票的详细信息。

在这个视图上,有一个带有一些按钮的 actionView。

其中一个按钮是“付款”。

点击付款时,会显示一个模式窗口。

但是,当我点击取消按钮时,它会删除所有视图并返回登录视图(初始视图)

发票视图

@IBAction func showActionAlert(_ sender: Any) {
let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)

let payButton = UIAlertAction(title: "Make Payment", style: .default, handler: { (action) -> Void in

    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let controller = storyboard.instantiateViewController(withIdentifier: "MakePaymentViewController")
    self.present(controller, animated: true, completion: nil)

})

let voidButton = UIAlertAction(title: "Void", style: .destructive, handler: { (action) -> Void in
})

let deleteButton = UIAlertAction(title: "Delete", style: .destructive, handler: { (action) -> Void in
})

let cancelButton = UIAlertAction(title: "Cancel", style: .cancel, handler: { (action) -> Void in })
alertController.addAction(payButton)
alertController.addAction(voidButton)
alertController.addAction(deleteButton)
alertController.addAction(cancelButton)
self.navigationController!.present(alertController, animated: true, completion: nil)

}

模态视图

 @IBAction func cancelButton(_ sender: Any) {
     let tmpController :UIViewController! = self.presentingViewController;
     self.dismiss(animated: false, completion: {()->Void in
         tmpController.dismiss(animated: true, completion: nil);
     });
 }

【问题讨论】:

    标签: swift view modal-dialog uitabbarcontroller


    【解决方案1】:

    我更改了 cancelButton 操作并且它起作用了:

    @IBAction func cancelButton(_ sender: Any) {
        dismiss(animated: true, completion: nil)
    }
    

    【讨论】:

      【解决方案2】:

      您从中展示它的控制器是您的 navigationController 导航堆栈所在的控制器。

      如果您从 navigationController 中呈现多个 viewControllers,然后从 parent/presentingViewController(即 navigationController)中关闭所有呈现的控制器,则所有呈现的 viewController 都会被解除.

      而不是像这样呈现它:

      self.navigationController!.present(alertController, animated: true, completion: nil)
      

      这样做

      self.present(alertController, animated: true, completion: nil)
      

      在解雇时做:

      self.dismiss(animated: true, completion: nil)
      

      【讨论】:

      • 我在 showActionAlert 上更改了它,但它仍然进入登录视图
      • 我添加了故事板的图片。模态是暗视图。登录视图是初始视图
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-04
      • 2020-03-24
      相关资源
      最近更新 更多