I'm fairly new to iOS development, but catching on pretty quickly.
I'm attempting to figure out how to create universal apps from the window-only template in xcode. I THOUGHT that i could add a main view to the main_window.xib by following these steps:
- Make a new window-based app template.
- Go to file > new file > uiviewcontroller subclass with XIB file.
- Open the main_window.xib and add a new view controller, with my new uiviewcontroller subclass as the selected NIB name in the inspector.
- Control-Drag from the window object to the new view controller, and add it as the rootViewController.
I thought that from here i had something that was essentially the same as the view-based template, but when i add in a segmented view controller, add the IBOutlet/IBAction in code, and then hook up the outlets and received actions in Interface Builder, the app crashes as it launches every time.
I'm positive that i'm missing a vital step in hooking up this process and would be greatful if anyone could offer the solution, as well as some general advice when setting up these sorts of things?
Thanks.
EDIT: Solved it by doing the following:
- Create new window based template.
- Create UIViewController Subclass, name it whatever you want.
- In AppDelegate.h, add
@class YourViewControllerName
before@interface
- Inside the @interface for appDelegate, add
YourViewControllerName *mainViewController;
- Then outside the @interface add
@开发者_如何学Goproperty (nonatomic, retain) IBOutlet YourViewControllerName *mainViewController;
- In AppDelegate.m add in
#import YourViewControllerName.h
at the top. - Add
@synthesize YourViewControllerName
. - In
ApplicationDidFinishLaunching
add:[self.window addSubView:mainViewController.view]
- Open MainWindow.xib in interface builder, drag in a new view controller from the library, and use the property inspector to change it's class to be YourViewControllerName, and select the corresponding NIB file from the drop-down menu.
- Control drag from the app delegate, which is the yellow box in IB, to your new;y created view controller, and hook up the mainViewController outlet you created.
VOILA! done. Solved all my problems.
Many many thanks for the help guys.
Make an IBOutlet for your custom view controller, called viewController of type MyViewController (or whatever you want your class to be named) in your app delegate, and make MyViewController subclass UIViewController. Next, in the MainWindow.xib file, add a new view controller from the library, being sure to set the class of this view controller to MyViewController (or whatever your class name is). Next, hook up the viewContoller outlet to the view controller in the MainWindow.xib file, and in your applicationDidFinishLaunching method, add this:
[window addSubview:viewContoller.view];
That should do it!
this s my documentation ,this may helps you.....
- create Window Based Application (name as your wise)
2.create UIviewcontroller class(.h & .m) with nib file
3.open appdelegate.h and import " view controller .h"(which created in step2)
- ADD @class [view controller class name] before (@interface appDelegate )
- ADD within @interface appDelegate view controller class name *alias Name; @property (nontoxic,retain)IBOutlet view controller class name *alias Name;
4.open appdelegate.m
1.@synthesize aliasname;
2.
-(void)applicationDidfinishLaunching:(UIApplication *)application
{
[window addsubView: aliasname.view];
[window makekeyAndVisible];
}
5.open mainwindow.xib
1.add UIviewcontroller from library
2.open property for UIviewcontroller ,add nib file name and class name
3.link window object with Uiviewcontroller using property
精彩评论