I have one class called MainMenu, which has a method called switchViews, with 2 parameters, an NSWindow and an NSView.
I then have the AppDelegate, which i want to use this method in the ‘applicationDidFinishLaunching’.
So in the AppDelegate.h i have imported the MainMenu.h and in the AppDelegate.m I use as follows:
MainMenu *theMainMenu = [[MainMenu alloc]] init];
[theMainMenu switchViews:param1:param2;
There are no warnings or errors, it just doesn’t call the method.
If i copy and paste the method instead of calling it, it works fine so it’s not a problem with the variables, it seems there is just an error running the method if it’s in a different class?
Any help would be greatly appreciated.
Thanks in advance
switchViews method:
- (void)switchViews:(NSWindow*)mainWindow:(NSView*)newView {
NSView *dummyView;
[theMainWindow setContentView:dummyView];
[theMainWindow setContentSize:newView.frame.size];
[theMainWindow setContentView:newView];
}
EDIT: sorry guys, it was just a typo.
SOLUTION: I was using the wrong parameter in the method call. Below is the working code:
- (void)switchViews:(NSWindow*)mainWindow:(NSView*)newView {
NSView *dummyView;
[mainWindow setContentView:dummyView];
[mainWindow setContentSize:newView.frame.size];
[mainWindow setContentView:newView];
}
If that’s your code, then it isn’t even running, because the build fails, because that code is invalid.
Assuming your actual code doesn’t contain syntax errors, nothing happening generally means you sent a message to
nil. Either-[MainMenu init]returnednil, or the implementation ofswitchViews::tried to send a message to an object it doesn’t have.Assuming you don’t have any statements in
-[MainMenu init]to returnnil, the latter case is more probable. Make sure that it creates whatever objects it needs to, or, if you mean for it to be nib-based, make sure that you have hooked up all of your MainMenu object’s outlets and that you didn’t forget to load the nib.Edit:
You named the method’s first argument variable
mainWindow, but then you send messages totheMainWindow.If the MainMenu object has an outlet named
theMainWindow, make sure that that’s hooked up, and remove the redundant first argument. Alternatively, kill off the outlet (or whatevertheMainWindowis) and usemainWindow.Also, since the AppDelegate (for some reason) is passing the window to the MainMenu object, make sure the AppDelegate actually has the window. Start by checking the value of “
param1” in the AppDelegate code.