0

I'm adding a view controller's view to my window in application:didFinishLaunchingWithOptions: but the view does not become visible. I'm not sure what's wrong.

Here's my app delegate code:

@class ToolBar;
@class MainViewController;

@interface AppDelegate : UIResponder <UIApplicationDelegate>

{
    UIWindow *Window;
    //UIToolbar *toolbar; 
}

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) MainViewController *mainViewController;
@property (strong, nonatomic) ToolBar *toolbar;

@end

#import "AppDelegate.h"
#import "MainViewController.h"
#import "ToolBar.h"

@implementation AppDelegate

@synthesize window = _window;
@synthesize mainViewController = _mainViewController;
@synthesize toolbar =toolbar;


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]autorelease];
    self.mainViewController = [[[MainViewController alloc]init]autorelease];
    [self.window addSubview:self.mainViewController.view];
    //[self.window makeKeyAndVisible];
    self.toolbar = [[[ToolBar alloc]init]autorelease];
    [self.window addSubview:toolbar.view];    
    [self.window makeKeyAndVisible];
    return YES;
 }
jscs
  • 63,694
  • 13
  • 151
  • 195
user1120133
  • 3,244
  • 3
  • 48
  • 90

1 Answers1

1

Well, to start with you're not setting the frame for your toolbar.

But why are you adding a toolbar to your app's main window? I would expect it to be a subview of your mainViewController's view.

Ashley Mills
  • 50,474
  • 16
  • 129
  • 160
  • i had it as the subview of the main controller but the problem i was having when my view controllers were flipping toolbar was also flipping. which i don't want that is why now i m adding toolbar as subview of the app delegate. Now I have separate view controller for uitoolbar and that is where i m adding as int with frame – user1120133 May 23 '12 at 16:34
  • Just to be clear - the app delegate is NOT a view, so you're not adding the toolbar as a subview of the app delegate - you're adding at as a subview of your app's main window. Either way, what you're doing is wrong. The toolbar should be a subview of a view controller's view. – Ashley Mills May 23 '12 at 22:14