开发者

UIViews firing an action in another UIViewController

开发者 https://www.devze.com 2022-12-22 22:05 出处:网络
My iPhone app is made of of a main tabControl开发者_Python百科ler with 4 main tabs.I have a situation where ViewController A loads ViewController B (using pushViewController).I now need to get back to

My iPhone app is made of of a main tabControl开发者_Python百科ler with 4 main tabs. I have a situation where ViewController A loads ViewController B (using pushViewController). I now need to get back to ViewController A and and trigger an action on A from B.

Getting back to A is easy all I have to do is :-

self.tabBarController.selectedIndex = 0;
[self.navigationController popViewControllerAnimated:YES];

this then causes the ViewController A to be visible.

But how do I then get ViewController B to fire an action on A?

I have tried to use:-

ViewControllerA  *aVC = ((ViewControllerA *)((UIViewController *)[self.tabBarC.tabBarController.viewControllers objectAtIndex:0]));
[aVC setAnnoSelected];

Only when I do that I get:-

-[UINavigationController setAnnoSelected]: unrecognized selector sent to instance 0x461d290

I have tried to use

[ViewControllerA performSelector:@selector(setAnnoSelected) withObject: nil afterDelay: 0.0];

But so far no joy.

Any ideas would be greatly appreciated.

Thanks Cheryl

P.S. This is a great site for help - thanks to anyone who has ever answered a question as you have helped me too.


It looks like your tabBarController's viewControllers are actually UINavigationControllers (you can see this by the unrecognized selector error). You probably want to look at that controller's own view controllers:

UINavigationController   *navController = (UINavigationController *) [self.tabBarController.viewControllers objectAtIndex: 0];
ViewControllerA          *controller = [navController.viewControllers objectAtIndex: 0];

[controller setAnnoSelected];

You might want to consider doing this with a notification instead, however, as this method is a little fragile.

0

精彩评论

暂无评论...
验证码 换一张
取 消