-1

I have an Page View Controller containing two Navigation Controllers, which are embedding view controllers.

enter image description here

Is it possible to pass data directly from the View Controller to the Page View Controller. I want to use the delegation pattern, but I think then I am supposed to delegate to the navigation controller first which delegates to the Page View controller again. Does anybody know an less complex solution?

Thanks in advance!

Robert Dresler
  • 10,580
  • 2
  • 22
  • 40
Womble Tristes
  • 393
  • 1
  • 4
  • 14

2 Answers2

0

I don't think is wise to use protocols here, you're diving too deep, is it not possible to use notifications?

In your view that should call delegate function:

NotificationCenter.default.post(name: Notification.Name("yourNotification"), object: your object)

Then in your pageViewController viewDidLoad:

NotificationCenter.default.addObserver(self, selector: #selector(yourFuncName), name: NSNotification.Name("yourNotification"), object: nil)
zheck
  • 298
  • 3
  • 11
0

In viewDidLoad from your "PageViewController", add

- (void)viewDidLoad {
    [super viewDidLoad];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(FooBar) name:@"FooBar" object:nil]; 
}

- (void) FooBar { 
NSLog(@"Foo"); 
};

Then call from the "ViewController"

[[NSNotificationCenter defaultCenter] postNotificationName:@"FooBar" object:nil];
TheAlphaGhost
  • 151
  • 10