问题描述
我有一个简单的测试项目,其中以UINavigationController
作为我的rootViewController
.
I have a simple test project with a UINavigationController
as my rootViewController
.
我按下第一个ViewController
,它带有一个+按钮,作为右栏按钮,我订阅它的水龙头以显示一个新的ViewController
(与上一个相同).推送功能按我的预期工作.
I push the first ViewController
which has a + button as right bar button item, I subscribe to its taps to present a new ViewController
(which is identical to the previous one).The push segue works as I expect.
UIKit
为我管理后退按钮,我认为是UINavigationController
在幕后制造了魔力.
UIKit
manages the back button for me and I think it is UINavigationController
that makes the magic behind the scene.
现在,我需要做的是订阅后退"按钮,但是我找不到执行该操作的方法.我尝试过
Now, what I need to do is subscribe to the back button, but I can't find how to do this.I have tried with
-
navigationController.navigationBar.backItem?.backBarButtonItem?.rx.tap
navigationController.navigationItem.backBarButtonItem?.rx.tap
但它们似乎为零,因此可选链接阻止了订阅.
navigationController.navigationItem.backBarButtonItem?.rx.tap
but they seem to be nil, so the optional chaining prevents subscription.
感谢您的帮助,卢卡-
推荐答案
我认为您最好的选择是在UINavigationController上使用运算符.
I think your best bet here is to use the operator on UINavigationController.
navigationController.rx.willShow
将触发.火灾发生时,您可以在最后一分钟进行清理.
navigationController.rx.willShow
will trigger whenever a view controller is about to be shown. You can do any last minute clean up when it fires.
这篇关于使用RxSwift/RxCocoa订阅UINavigationController后退按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!