I have an universal application that had all views in the same file MainWindow.xib. Today I decided to separate these views into their respective xib files (to have MainMenuController.h, MainMenuController.m and MainMenuController.xib for example). Now I can't receive and IBActions. Here is what I did step by step:
I created a new .xib file named MainMenuController.xib and set it's File's Owner to the already existing MainMenuController class.
I copied the view corresponding to the MainMenuController from the MainWindow.xib file and pasted it into the newly created MainMenuController.xib. I set the File's Owner's view to be the newly pasted view (connected in IB).
In the info.plist, I removed the entries for the "Main xib file base name", so the app doesn't open with MainWindow.xib automatically.
I modified the app delegate to create the window programatically and add the MainMenuController to it with this code:
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; mainMenuController = [[MainMenuController alloc] init]; self.window.rootViewController = mainMenuController; [self.window makeKeyAndVisible]; [mainMenuController release];
"mainMenuController" and "window" are instance variables and also declared as properties.
I have only one AppDelegate class and main.m contains:
int main(int argc, char *argv[]) { @autoreleasepool { return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); }}
Now when the application opens, I see the MainMenuController's view come up. At this point I began to wire the IBOutlets and IBActions in the pasted view in the new xib file. Although I see the IBOutlets in the File's Owner and connect them properly, the function for the IBAction is never called when I press the button.
Possible errors that came to my mind: (1) application window not properly set, it doesn't pass events, (2) something is stuck or lost while copying the view, still pointing to the old owner (3) something wrong stuck in xcode project
What do you think the problem could be? Is it one of the above? How can I solve this? Any help is appreciated.
Thanks in advance.