简体   繁体   中英

Load an XIB from a view controller of another XIB (iPhone)

This is my first post and I'm pretty new to this stuff but here is my question and I hope you can help :)

So I made a game screen and now want to add a Main Menu to the beginning. So I added a new View Controller Subclass and now have an IBAction that is from a button that will load the game screen.

#import <UIKit/UIKit.h>


@interface MainMenuViewController : UIViewController{
  IBOutlet  UIButton *classicMode;
  IBOutlet  UIButton *timedMode;
}    

@property (nonatomic, retain) IBOutlet UIButton *classicMode; 
@property (nonatomic, retain) IBOutlet UIButton *timedMode; 



- (IBAction) classicModeButton:(id) sender;
- (IBAction) timedModeButton:(id) sender;
@end

So now I went into my .m and set the IBAction

- (IBAction) classicModeButton:(id)sender{


} 

But I've tried using initWithNibName and specifying my other view controller xib, and it runs with no errors, but when I tap the button I have linked in IB it always crashes and says that it received the signal SIGABRT. Any help would be greatly appreciated. :)

You are probably hitting the problem described in this post. You need to set your controller as self.window.rootViewController instead of adding it as subview of the self.window in your app delegate code.

You need to post more of your code but you most likely need to create a navigation controller to push the view controller onto. The navigation controller manages the transition of views so is necessary to perform switches from one view to another.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM