diff --git a/Sources/Controllers/OASuperViewController.m b/Sources/Controllers/OASuperViewController.m index ea32aa2d1c..b85407f91a 100644 --- a/Sources/Controllers/OASuperViewController.m +++ b/Sources/Controllers/OASuperViewController.m @@ -21,21 +21,38 @@ @implementation OASuperViewController #pragma mark - Initialization // use addNotification:selector: method here -// notifications will be automatically added in viewWillAppear: and removed in dealloc +// notifications will be automatically added in viewDidLoad: and removed in dealloc - (void)registerNotifications { } +// use addObserver: method here +// observers will be automatically added in viewDidLoad: and removed in dealloc +- (void)registerObservers +{ +} + // do not override - (void)addNotification:(NSNotificationName)name selector:(SEL)selector { [NSNotificationCenter.defaultCenter addObserver:self selector:selector name:name object:nil]; } -// use addObserver: method here -// observers will be automatically added in viewDidAppear: and removed in viewWillDisappear: -- (void)registerObservers +// do not override +- (OAAutoObserverProxy *)addObserver:(OAAutoObserverProxy *)observer { + [_observers addObject:observer]; + return observer; +} + +- (void)registerNotificationsAndObservers +{ + // for content size category + [self addNotification:UIContentSizeCategoryDidChangeNotification selector:@selector(onContentSizeChanged:)]; + // for other + [self registerNotifications]; + + [self registerObservers]; } - (void)unregisterNotificationsAndObservers @@ -46,13 +63,6 @@ - (void)unregisterNotificationsAndObservers [observer detach]; } -// do not override -- (OAAutoObserverProxy *)addObserver:(OAAutoObserverProxy *)observer -{ - [_observers addObject:observer]; - return observer; -} - #pragma mark - UIViewController - (void)viewDidLoad @@ -62,24 +72,12 @@ - (void)viewDidLoad [self addAccessibilityLabels]; _observers = [NSMutableArray array]; -} -- (void)viewDidAppear:(BOOL)animated -{ - [super viewDidAppear:animated]; - - // for content size category - [self addNotification:UIContentSizeCategoryDidChangeNotification selector:@selector(onContentSizeChanged:)]; - // for other - [self registerNotifications]; - - [self registerObservers]; + [self registerNotificationsAndObservers]; } -- (void)viewWillDisappear:(BOOL)animated +- (void) dealloc { - [super viewWillDisappear:animated]; - [self unregisterNotificationsAndObservers]; }