简体   繁体   English

出现 VC 时显示取消按钮,按下同一个 VC 时不显示取消按钮

[英]Display cancel button when the VC is presented, don't display cancel button when the same VC is pushed

I have a ViewController that need to display in two places.我有一个需要在两个地方显示的 ViewController。

In first place, the VC need to present and dismiss using a cancel button in its navigation bar.首先,VC 需要使用其导航栏中的取消按钮来展示和关闭。

In second place, the VC need to push to a navigation stack(its presented modally too) and cannot close (user have to use the back button in navigation stack).其次,VC 需要推送到导航堆栈(它也以模态方式呈现)并且无法关闭(用户必须使用导航堆栈中的后退按钮)。

I can display the VC in both places correctly but cannot use the close button properly.我可以在两个地方正确显示 VC,但不能正确使用关闭按钮。 When I add the cancel bar button item to the VC, it appears in both scenarios.当我将取消栏按钮项添加到 VC 时,它在两种情况下都会出现。 How can I show the cancel button when the VC is presented and hide it when the VC is pushed?如何在 VC 出现时显示取消按钮并在 VC 被按下时隐藏它?

Using isBeingPresented you can manage your cancel button,使用 isBeingPresented 你可以管理你的取消按钮,

        if self.isBeingPresented {
           debugPrint("Controller is Presented")
        } else {
            debugPrint("Controller is Pushed")
         }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 按下“取消”按钮后,UISearchController取消VC - UISearchController dismisses VC upon hitting cancel button 单击按钮时如何显示删除取消弹出窗口 - how to display delete cancel popup when clicking a button 当作为子视图添加到UINavigationBar时,UISearchBar不显示“取消”按钮 - UISearchBar does not display Cancel button when added as subview to UINavigationBar 第一次推送vc时,如何弹出vc 12次,如何弹出? - how to pop when first pushed vc then presented modal vc 12 times? UIImagePickercontroller取消按钮在iPad中不显示 - UIImagePickercontroller cancel button not display in iPad 按下按钮时显示自定义覆盖图像 - Display custom overlay image when button is pushed 轻按按钮时取消UIGestureRecognizer吗? - Cancel UIGestureRecognizer when a button is tapped? 当我使用发布通知时,社交框架的取消按钮不隐藏控制器,而是隐藏警报 - When I use Post Notification then cancel button of Social framework don't hide Controller but hides alert 如何在UITableViewCell中显示红色的“取消”按钮? - How to display red “Cancel” button in UITableViewCell? 按下取消时显示警报视图并停留在同一视图控制器上 - Show alert view and stay on same view controller when cancel is pushed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM