iOS:Window对象为零

时间:2012-08-04 19:47:01

标签: iphone uitabbarcontroller uiapplicationdelegate ios5.1 uiwindow

我有一个app委托,我需要添加自定义标签栏控制器来覆盖UITabbarController。我创建了Window用户界面,引用了Appdelegate的Window对象的Window。将File的所有者设为UIApplication,添加了NSObject并将身份类更改为我的委托,添加了UITabbarController并将身份类更改为我的自定义tabbar控制器。现在我看到非常不寻常的是didFinishLaunchingWithOptions中的Window对象为零,所以我在屏幕上看不到任何内容。我的自定义tabbar控制器对象也是零!以下是我的新窗口结构和main.m.谁能告诉我我哪里做错了?感谢。

int main(int argc, char *argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}


Appdelegate.h

#import <UIKit/UIKit.h>
#import "CustomTabBarController.h"

@interface AppDelegate : UIResponder <UIApplicationDelegate, UITabBarControllerDelegate>

@property (strong, nonatomic) IBOutlet UIWindow *window;

@property (strong, nonatomic) IBOutlet CustomTabBarController *tabBarController;

@end

Appdelegate.m

#import "AppDelegate.h"

@implementation AppDelegate

@synthesize window = _window;
@synthesize tabBarController = _tabBarController;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    if(_window == nil) // This is true for self.Window as well!
        NSLog(@"nil");
    if(_tabBarController.view == nil)
        NSLog(@"nil");
    [self.window addSubview:self.tabBarController.view];
    [self.window makeKeyAndVisible];
    return YES;
}  

enter image description here

1 个答案:

答案 0 :(得分:2)

我解决了这个问题......缺少两件事。

  1. 文件的所有者检查员,参考出口委托给AppDelegate。
  2. 在项目的目标设置中,将主界面设置为新创建的窗口。