abdus.me
abdus.me

Reputation: 1819

sending message from topViewController to rootViewController in iOS

I am developing an application for iPhone in which I need to send a message from topViewController to rootViewController.

One solution might be that make delegate methods in each VC in navigation stack and call accordingly so that message will reach at rootViewController. But in this scenario message has to pass through whole navigation stack.

Can any body help me on this with best approach

Thanks

Upvotes: 1

Views: 388

Answers (2)

AppleDelegate
AppleDelegate

Reputation: 4249

In any of the topViewController methods you can extract the navigation stacks's rootViewController by

 [self.navigationController.viewControllers objectAtIndex:0];

Upvotes: 1

iDev
iDev

Reputation: 23278

One option is to access rootViewcontroller as,

RootViewController *rootViewController = (RootViewController *)[self.navigationController.viewControllers objectAtIndex:0];

and then do the necessary operation on this object. navigationController.viewControllers returns all the viewControllers in the navigation stack.

Upvotes: 2

Related Questions