tags:

views:

502

answers:

2

I am new to iPhone development. I have been looking at samples and make a sample for myself, but am stuck.

I am trying to add a view to the AppDelegate class so it will show when the app is launched.

code is as follows

- (void)applicationDidFinishLaunching:(UIApplication *)application {    

    [window addSubview:viewController.view];
    [window makeKeyAndVisible];

}

However this does not show the .xib tied to the viewController but the MainWindow.xib is shown.

I think it is being added since when I shut the app down the content of the desired view is shown as it is shutting down.

I thought the addSubview puts the view in front of all others when called.

Is there something I should do in the Interface Builder to set priorities?

Updated:

By lowering the alpha attribute to 0.0 for the UIWindow for MainWindow.xib made the view that was added by addSubview apear. However this is prob not the right thing to do.

A: 

In the interface builder, is the ViewControler is properly bound to the viewController variable in your AppDelegate class?

In your AppDelegate.h, there should be something like, IBOutlet UIViewController *viewController;

In the interface builder, open MainWindow.xib, right click the App Delegate item and see whether some value has been assigned to the viewController attribute. If not, drag the 'dot' to the your ViewController item in interface builder.

ravinsp
Thank you for the response, yes I have a pointer of the same class that I want to add in the AppDelegate class, and it is connected in the Interface Builder. I'll keep looking into it and update any new info.
Saifis
A: 

Ok I found out what was wrong, it was a really careless mistake I made when I was using the Interface Builder.

I mistakenly created the xib to add to the MainWindow.xib as a window.xib and not a view.xib.

Once recreating it as a view.xib everything went fine.

...so embarrassed I have made such a stupid mistake, hope it would be useful to others.

Saifis