[英]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.