JVS
JVS

Reputation: 2682

NSNotification for all views at once

I am trying to addObserver to all my views, when I start my application. When there is a post coming I want to display a Modal View on top of the current ViewController.

Is there a way to install it directly on every View or do I need to do the

viewWillAppear : add
viewDidDisappear : remove

workaround each time ?

Upvotes: 0

Views: 67

Answers (2)

neprocker
neprocker

Reputation: 170

Create parent class like this and subclass all other classes

import UIKit

class TemplateClassVC: UIViewController {


override func viewWillAppear() {
}

override func viewDidDisappear() {
}


}

and find top viewcontroller like this Get top most UIViewController

Upvotes: 1

alexburtnik
alexburtnik

Reputation: 7741

  1. You could have created one superclass for all you view controllers and override viewWillAppear/viewDidDisappear there.
  2. If there is no exception and you want to present a modal view controller no matter what view controller is currently on screen, you can present it over self.window.rootViewController in AppDelegate's didReceiveRemoteNotification method.

Upvotes: 1

Related Questions