ios - 向模态推送转场添加条件

标签 ios swift

<分区>

我使用导航 Controller 和模态显示转场。 如果 [condition] 不为真,我想阻止我的第二个 View Controller 的后退按钮,例如当用户按下后退按钮时添加警告“你不能返回直到 [condition]”。

不知道有没有人知道怎么解决!

谢谢

最佳答案

您需要为后退栏按钮项添加自定义操作。

@IBAction func backPressed(_ sender: UIBarButtonItem) {
     if !myCondition {
          let alert = UIAlertViewController(title: "Alert", message: "Please fulfill the condition")
          let action = UIAlertAction(title: "OK", .default)
          self.present(alert, animated: true)
          return
     }
     navigationController?.popViewController(animated: true)
}

或者您可以只使用代码中的正常目标操作。

myBarButton.addTarget(self, selector: #selector(backButtonPressed(_:)))

抱歉语法不正确。

关于ios - 向模态推送转场添加条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50375746/

相关文章:

ios - 以编程方式加载新的 ViewController

ios - Swift:如何确保 seque 在 http 任务完成之前不运行?

objective-c - Swift - 如何更改仅获取属性的值

ios - 解析数据库在应该创建新对象时正在替换对象

swift - 如何在 SwiftUI 中使用 ForEach 仅更改一个核心数据项的切换?

iphone - 如何模糊除 2 个节点之外的所有内容。 Spritekit( swift )

ios - 使用 goBack 时未触发 webViewDidFinishLoad

ios - 带有自定义单元格的 UICollectionView 破坏 UICollectionViewDataSource 协议(protocol)

iphone - 带有段 Controller 的 UIPopOverController

ios - 从 AppStore 或 TestFlight 启动时应用程序崩溃但在其他地方运行良好