Skip to content

Commit be8ee78

Browse files
authored
Update RenditionListViewController.swift (#19)
1 parent e5e5057 commit be8ee78

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

Samra/UI/Rendition/RenditionListViewController.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ class RenditionListViewController: NSViewController {
2727
var collection: RenditionCollection
2828
let fileURL: URL
2929

30+
private var scrollObserver: NSObjectProtocol?
31+
3032
init(catalog: CUICatalog, collection: RenditionCollection, fileURL: URL) {
3133
self.catalog = catalog
3234
self.collection = collection
@@ -99,9 +101,10 @@ class RenditionListViewController: NSViewController {
99101
view = scrollView
100102
view.frame.size = CGSize(width: 724, height: 676)
101103

102-
NotificationCenter.default.addObserver(forName: NSScrollView.didEndLiveScrollNotification, object: scrollView, queue: nil) { [unowned self] _ in
103-
let vc = splitViewParent?.splitViewItems[0].viewController as? TypesListViewController
104-
guard let vc, let currentSection = collectionView.indexPathsForVisibleItems().first?.section else {
104+
let observer = NotificationCenter.default.addObserver(forName: NSScrollView.didEndLiveScrollNotification, object: scrollView, queue: nil) { [weak self] _ in
105+
guard let self = self else { return }
106+
let vc = self.splitViewParent?.splitViewItems[0].viewController as? TypesListViewController
107+
guard let vc, let currentSection = self.collectionView.indexPathsForVisibleItems().first?.section else {
105108
return
106109
}
107110

@@ -111,6 +114,8 @@ class RenditionListViewController: NSViewController {
111114
vc.ignoreChanges = false
112115
}
113116

117+
self.scrollObserver = observer
118+
114119
collectionView.registerForDraggedTypes(NSImage.imageTypes.map { .init($0) })
115120
collectionView.setDraggingSourceOperationMask(.every, forLocal: true)
116121
collectionView.setDraggingSourceOperationMask(.every, forLocal: false)
@@ -160,6 +165,9 @@ class RenditionListViewController: NSViewController {
160165
}
161166

162167
deinit {
168+
if let observer = scrollObserver {
169+
NotificationCenter.default.removeObserver(observer)
170+
}
163171
print("And I'm tripping and falling..")
164172
}
165173
}

0 commit comments

Comments
 (0)