views:

23

answers:

1

Is the possible for multiple UIViewControllers working at the same time? Consider the following window:

         +-----------------+         
         |  +-----+        |
         |  |     |        |
         |  |  A  |    C   |
         |  |     |        |
         |  +-----+        |
         |                 |
         |       +-----+   |
         |       |  B  |   |
         |       +-----+   |
         |                 |
         +-----------------+

C is the first UIViewController added to the window.

In viewDidLoad of C_ViewController, I added a NIB (A) by:

A_ViewController *avc = [[A_ViewController alloc] initWithNibName:@"A_ViewController" bundle:nil];
[self.view addSubview:avc.view];
[avc release];

A_ViewController is loaded and shown properly. However, if linking any event from the A_ViewController.xib to IBOutlet in A_ViewController.m (e.g. buttonClick), there is an error when the event is fired:

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString buttonClicked:]: unrecognized selector sent to instance 0x5937a40'

The question, is it possible to have multiple UIViewController working at the same time? In this example, one for C, one for A and one for B.

ADDED: the header file of C_ViewController

    @class A_ViewController;

    @interface C_ViewController : UIViewController {
        A_ViewController *avc;
    }

    @property (nonatomic, retain) IBOutlet A_ViewController *avc;

    @end

SOLUTION:

  A_ViewController *a = [[A_ViewController alloc] initWithNibName:@"A_ViewController" bundle:nil];
  [self.view addSubview:a.view];
  self.avc = a; // added this to fix!! Thanks
  [a release];
A: 

Did you tried retaining your A_ViewController instance ? I'm not sure the viewcontroller is retained by it's view.

Charter
@Charter, I added the header file in the question.
ohho
@Charter, thanks! Fixed.
ohho