Quote:
Originally Posted by mikolo
Hi,
i have defined two UIViews and one action in my UIViewController like this:
PHP Code:
#import <UIKit/UIKit.h>
#import "LoginView.h"
#import "ContactListView.h"
@interface NowHereViewController : UIViewController {
IBOutlet LoginView *loginView;
IBOutlet ContactListView *contactListView;
}
-(void)swichView:(id)sender;
@end
first i load the loginView in my view in NowHereViewController.m like this:
PHP Code:
- (void)viewDidLoad {
NSLog(@" ---- viewDidLoad ---- ");
[self.view addSubview:loginView];
[loginView initLoginView];
[super viewDidLoad];
}
now i want to call the function swichView in the NowHereViewController from the loginView again?
How can i do this?
Thanxxx for help.
|
I had this same problem myself.
There's probably an easier way but here's how I solved it.
Add this to your view.h file
Code:
NowHereViewController *controller;
Make it a property in the .h and synthesize it in the .m file.
You will use controller to access the controller.
In the viewDidLoad of your viewcontroller add this line:
Code:
self.view.controller = self;
This sends a pointer of your view controller to the view, so it can access it.
Just be careful with this though! If the viewcontroller is non-existent the view will crash when its calls for it. You need to ensure that if a new view is made it will also know of this change. I add a if(self.controller != nil) whenever I call the controller, just so that if I forget to set the controller, it won't ruin everything!
Hope it works for you!