views:

572

answers:

1

I have two view controllers (viewControllerA and viewControllerB) with their own views. When the user touches a button in the view of viewControllerA, I am able to load the view of the viewControllerB.

However, I don't know how to invoke a method in viewControllerB's class!

A: 

Without much info to go on I'll assume that both A & B are of the same class (though they wouldn't have to be). You could always declare a property that would then point from one to the other:

MyViewController.h:

@interface MyViewController : UIViewController {
    MyViewController *altViewController;
}

@property (nonatomic, retain) MyViewController *altViewController
@end

Just be sure that once instantiated you populate that property with a pointer to the other VC. Then you can easily call a method on the other view controller simply by: [altViewController doMethod];

Meltemi
Hi - Thanks for the reply. Since I am a noob, I have hard time with your suggestion. Can you please - pretty please - give an example! Many thanks in advance.Sam
set up VCA with a pointer to VCB as I've shown you above. Then after you have instantiated VCB with something like: MyViewController *vcb = [[MyViewController alloc] init] // or initWithNibName; then you'll need to set VCA's altViewController to point towards VCB: self.altViewController = vcb; It's hard to go much further without knowing what, exactly, you're trying to do? Will both VC's be presenting data at once? Perhaps each managing small UIViews on the screen? Or is one pushed out of the way when the other is displayed. You might try some of the iPhone tutorials available around the web.
Meltemi
To clarify, when VCB is loaded, VCA is unloaded and vice versa. And yes, the VCs have their own views. But thanks very much for your explanation and example. I'll play with it and let you know.