将视图作为子视图添加到我的应用程序窗口但不显示

时间:2012-05-23 15:41:53

标签: objective-c cocoa-touch uiview uiwindow

我正在application:didFinishLaunchingWithOptions:中将视图控制器的视图添加到我的窗口,但视图不可见。我不确定是什么问题。

这是我的应用委托代码:

@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;
 }

1 个答案:

答案 0 :(得分:1)

好吧,首先,你没有为工具栏设置框架。

但是为什么要在应用的主窗口中添加工具栏?我希望它是你的mainViewController视图的子视图。

相关问题