How to set Main Inerface in xCode programatically - xcode

I am using Apples MultipleDetailViews http://developer.apple.com/library/ios/#samplecode/MultipleDetailViews/Introduction/Intro.html
for template as a source for my iPad app. The template is using a splitviewController in the interface builder (MainWindow). In the iPhone/iPad Deployment info of the target, MainWindow is set as the "Main Interface".
I want my app to also run on iPhone. This means I need to load a different xib when the app is run on an iPhone. I must then remove "MainWindow" from "Main Interface" because the app will crash when I load on an iPhone due to the splitViewController.
The AppDeleagte of the template look like this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.window.rootViewController = self.splitViewController;
[self.window makeKeyAndVisible];
}
If I remove "Main Window" from "Main Interface", how do I then need to change the APpDelegate, or maybe I need to change the MainWindow.xib to also work for iPhone?

I found the answer myself, and I am ashamed about how simple it really was. There is one "Main Interface" for iPhone, and one for iPad :-S. All this messing around for nothing :-(

Related

xcode 4.5.2 Can't make tabbared application

I have xcode 4.5.2. I've tried for a whole day but i couldn't manage to find an appropriate tutorial or sample to create a tab bar application
If i create a tabbed application, i don't know how to add tabs into controller.
If i create an empty application, i can not start it with tab bar controller on window.
I created a xib file. Make it the main source interface source in targets. Add a window and a tabbarcontroller there and link them with the outlets of the appDelegate.
In appDelegate.m in the didFinishLaunchingWithOptions i add the following code
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
[self.window addSubview:self.tabbarController.view];
[self.window makeKeyAndVisible];
and nothing helps.
What's the matter?
How can I do that?
Look at this tutorial may help you ,
Creating a Tab Bar Application Using Storyboards.

Program received signal SIGABRT error

I'm developing an iPhone app in which I have to call a REST service from iPhone. I did it successfully and got the response successfully. But later I have changed the xib file so that I want to display the output on a label. Then after changing the xib file when I run the application I'm getting the following exception:
Program received signal SIGABRT
in the following code? Since I'm a beginner in iPhone development, I don't know how to fix this error. Here is my code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
self.window.rootViewController = self.viewController; ///error at this line///
[self.window makeKeyAndVisible];
return YES;
}
How to fix this error?
Thanks!
In the IphonedevsdkViewController XIB you have to connect the topmost view to the view outlet of the File Owner.

Why does iphone simulator in xcode 4.3.2 come up with a blank white screen?

I have a major problem. My app was working perfectly fine back in xcode 4.2 and in iOS 5.0. However, when I updated to xcode 4.3.2 and iOS 5.1, I ran into an issue.
When I try running my app now, ios simulator comes up with my splash screen and then a blank white screen with a status bar. I also get
2012-04-08 20:46:48.025 Birdflix[67666:fb03] Application windows are expected to have a root view controller at the end of application launch
in the log.
Please help, I really need to publish my app. Thanks in advance.
Please set self.window.rootViewController in
the application:didFinishLaunchingWithOptions: method in AppDelegate.m.
Sorry, I haven't Xcode4.3.2, not always say rightly.
xcode 4.2, don't use MainWindow.nib, so you should specify self.window.rootViewController.
the rootViewController is the ViewController that AppDelegate's view controller in
previous version's MainWindow.nib.
Suppose the class is RootViewController, then
#import "RootViewController.h"
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.window.rootViewController = [[RootViewController alloc] init];
[self.window.makeKeyAndVisible];
return YES:
}

How does window management work in Mac development for MenuBar apps?

I'll preface this by saying this is my first Mac application, though I've been building iOs apps for some time.
I've got a menu bar app (system tray app) by which I mean I've got this.
I now want to show an NSWindow I've created in Interface Builder so I've created a class that's derived from NSWindow. Made my class the Window's delegate and from the App Delegate I do this:
MyClass *myClass = [[MyClass alloc] init];
[myClass display];
[myClass center];
[NSApp activateIgnoringOtherApps:YES];
[viewer makeKeyAndOrderFront:nil];
This seems to show a window without the standard window buttons (minimise, maximise, close) rather than the window I've defined.
Is this the right way to be showing windows? and how should the Window be defined so it shows my designed interface?
In Windows Forms programming this would be:
Form myForm = new Form();
myForm.Show();
You rarely need to subclass NSWindow unless you want to override a window's behavior. A more typical usage scenario would be to use an instance of NSWindowController or a subclass of NSWindowController to manage the window, by making that class the File's Owner in Interface Builder. Once this is done, to grab an instance of the window use:
NSWindowController *wc = [[NSWindowController alloc] initWithWindowNibName:#"NIBNAMEHERE"];
[wc showWindow:nil];
Another alternative in your app would be to add an NSWindow IBOutlet to your app delegate, and load the window in your app delegate with:
[NSBundle loadNibNamed:#"NIBFILENAME" owner:self];
[_window makeKeyAndOrderFront];

iPad: Launch MainWindow.xib's primary view without using InterfaceBuilder confi

I get really confused using InterfaceBuilder to setup the main window xib file's primary controller view. Is there a good example or simple way to launch the ViewController I want to show by default in the Application Delegate instead of setting it up in InterfaceBuilder's MainWindow.xib file?
you can show your view by code as
FirstViewController *fvc = [[FirstViewController alloc] init];
[window addSubView:fvc];

Resources