}
fileprivate extension MineAboutViewController {
@@ -42,7 +51,7 @@ fileprivate extension MineAboutViewController {
func bindGestureToContactUsAction() {
contactUsBtn.rx.tap
.asObservable()
- .subscribe { (_) in
+ .subscribe { [unowned self] _ in
let webVC = WebViewController(title: "联系我们",
path: "https://pai.ai/page/contact_us")
self.navigationController?.pushViewController(webVC)
@@ -52,7 +61,7 @@ fileprivate extension MineAboutViewController {
func bindGestureToScoreAction() {
scoreBtn.rx.tap
.asObservable()
- .subscribe { (_) in
+ .subscribe { _ in
guard let url = URL(string: "https://itunes.apple.com/cn/app/pai-aipaiai/id1163960351?mt=8") else {
return
}
@@ -63,7 +72,7 @@ fileprivate extension MineAboutViewController {
func bindGestureToUserAgreementAction() {
userAgreementBtn.rx.tap
.asObservable()
- .subscribe { (_) in
+ .subscribe { [unowned self] _ in
let webVC = WebViewController(title: "用户协议",
path: "https://pai.ai/page/user_agreement")
self.navigationController?.pushViewController(webVC)
@@ -78,3 +87,4 @@ extension MineAboutViewController: Storyboarded {
return UIStoryboard.mine.instantiateViewController(type: MineAboutViewController.self)
}
}
+
@@ -25,8 +25,6 @@ class MineCoordinator: BaseCoordinator<Void> {
|
||
| 25 | 25 |
mineViewController.delegate = self |
| 26 | 26 |
return didCancel |
| 27 | 27 |
} |
| 28 |
- |
|
| 29 |
- override func listenDeallocate() {}
|
|
| 30 | 28 |
} |
| 31 | 29 |
|
| 32 | 30 |
extension MineCoordinator: MineViewControllerDelegate {
|
@@ -46,7 +44,7 @@ extension MineCoordinator: MineViewControllerDelegate {
|
||
| 46 | 44 |
|
| 47 | 45 |
func didSelect(_ item: MineItem) {
|
| 48 | 46 |
mineViewController.dismissController() |
| 49 |
- |
|
| 47 |
+ deallocatedDispose.dispose() |
|
| 50 | 48 |
let vc: UIViewController |
| 51 | 49 |
switch item {
|
| 52 | 50 |
case .group: |
@@ -58,8 +56,8 @@ extension MineCoordinator: MineViewControllerDelegate {
|
||
| 58 | 56 |
case .about: |
| 59 | 57 |
vc = makeMineAboutViewController() |
| 60 | 58 |
} |
| 61 |
- |
|
| 62 |
- vc.rx.deallocated.subscribe(onNext: { _ in
|
|
| 59 |
+ |
|
| 60 |
+ vc.rx.deallocating.subscribe(onNext: { _ in
|
|
| 63 | 61 |
self.didCancel.onNext(()) |
| 64 | 62 |
}).disposed(by: disposeBag) |
| 65 | 63 |
} |
@@ -103,8 +101,8 @@ fileprivate extension MineCoordinator {
|
||
| 103 | 101 |
|
| 104 | 102 |
func makeMineAboutViewController() -> MineAboutViewController {
|
| 105 | 103 |
let vc = MineAboutViewController.instantiate() |
| 106 |
- navigationController.pushViewController(vc) |
|
| 107 |
- |
|
| 104 |
+ navigationController.pushViewController(vc, animated: true) |
|
| 105 |
+ print(navigationController) |
|
| 108 | 106 |
return vc |
| 109 | 107 |
} |
| 110 | 108 |
|
@@ -7,7 +7,7 @@ |
||
| 7 | 7 |
// |
| 8 | 8 |
|
| 9 | 9 |
import RxSwift |
| 10 |
-import Foundation |
|
| 10 |
+import UIKit |
|
| 11 | 11 |
|
| 12 | 12 |
public class BaseCoordinator<ResultType> {
|
| 13 | 13 |
|
@@ -15,6 +15,7 @@ public class BaseCoordinator<ResultType> {
|
||
| 15 | 15 |
|
| 16 | 16 |
let disposeBag = DisposeBag() |
| 17 | 17 |
var didCancel = PublishSubject<Void>() |
| 18 |
+ var deallocatedDispose = Disposables.create() |
|
| 18 | 19 |
var navigationController: UINavigationController |
| 19 | 20 |
var viewController: UIViewController |
| 20 | 21 |
|
@@ -25,7 +26,13 @@ public class BaseCoordinator<ResultType> {
|
||
| 25 | 26 |
init(navigationController: UINavigationController, viewController: UIViewController) {
|
| 26 | 27 |
self.viewController = viewController |
| 27 | 28 |
self.navigationController = navigationController |
| 28 |
- listenDeallocate() |
|
| 29 |
+ |
|
| 30 |
+ deallocatedDispose = viewController.rx.viewDidDisappear.subscribe(onNext: {[weak self] _ in
|
|
| 31 |
+ guard let `self` = self else { return }
|
|
| 32 |
+ if !self.navigationController.viewControllers.contains(viewController) {
|
|
| 33 |
+ self.didCancel.onNext(()) |
|
| 34 |
+ } |
|
| 35 |
+ }) |
|
| 29 | 36 |
} |
| 30 | 37 |
|
| 31 | 38 |
private func store<T>(coordinator: BaseCoordinator<T>) {
|
@@ -33,6 +40,7 @@ public class BaseCoordinator<ResultType> {
|
||
| 33 | 40 |
} |
| 34 | 41 |
|
| 35 | 42 |
private func free<T>(coordinator: BaseCoordinator<T>) {
|
| 43 |
+ print(coordinator) |
|
| 36 | 44 |
childCoordinators[coordinator.identifier] = nil |
| 37 | 45 |
} |
| 38 | 46 |
|
@@ -48,13 +56,4 @@ public class BaseCoordinator<ResultType> {
|
||
| 48 | 56 |
func start() -> Observable<ResultType> {
|
| 49 | 57 |
fatalError("Start method should be implemented.")
|
| 50 | 58 |
} |
| 51 |
- |
|
| 52 |
- func listenDeallocate() {
|
|
| 53 |
- navigationController.rx.willShow.subscribe(onNext: {[weak self] (_, _) in
|
|
| 54 |
- guard let `self` = self else { return }
|
|
| 55 |
- if !self.navigationController.viewControllers.contains(self.viewController) {
|
|
| 56 |
- self.didCancel.onNext(()) |
|
| 57 |
- } |
|
| 58 |
- }).disposed(by: disposeBag) |
|
| 59 |
- } |
|
| 60 | 59 |
} |