Skip to content

Commit

Permalink
Fixed a bug that mistakenly invalidate childKeyValueObservation
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiar committed Jun 18, 2019
1 parent 7595f41 commit e674e83
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Source/Content/SegementSlideContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ extension SegementSlideContentView {
}

private func clearAllReusableViewControllers() {
NotificationCenter.default.post(name: SegementSlideContentView.willClearAllReusableViewControllersNotification, object: nil, userInfo: nil)
NotificationCenter.default.post(name: SegementSlideContentView.willClearAllReusableViewControllersNotification, object: viewController, userInfo: nil)
for (_, value) in viewControllers {
guard let childViewController = value as? UIViewController else { continue }
childViewController.view.removeAllConstraints()
Expand Down
7 changes: 5 additions & 2 deletions Source/General/SegementSlideViewController+setup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,13 @@ extension SegementSlideViewController {
}

private func observeWillClearAllReusableViewControllersNotification() {
NotificationCenter.default.addObserver(self, selector: #selector(willClearAllReusableViewControllers), name: SegementSlideContentView.willClearAllReusableViewControllersNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(willClearAllReusableViewControllers(_:)), name: SegementSlideContentView.willClearAllReusableViewControllersNotification, object: nil)
}

@objc private func willClearAllReusableViewControllers() {
@objc private func willClearAllReusableViewControllers(_ notification: Notification) {
guard let object = notification.object as? SegementSlideViewController, object === self else {
return
}
childKeyValueObservation?.invalidate()
childKeyValueObservation = nil
}
Expand Down

0 comments on commit e674e83

Please sign in to comment.