Multiple UIViewController working at the same time?
Is the possible for multiple UIViewControllers working at the same time? Consider the following window:
+-----------------+
| +-----+ |
| | | |
开发者_如何学JAVA | | 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];
Did you tried retaining your A_ViewController instance ? I'm not sure the viewcontroller is retained by it's view.
精彩评论