0

我有一个应用程序委托,我需要添加自定义标签栏控制器来覆盖UITabbarController。我创建了Window用户界面,参考Appdelegate的Window对象窗口。将File的所有者改为UIApplication,添加NSObject并将身份类更改为我的委托,添加了UITabbarController并将身份类更改为我的自定义Tabbar控制器。现在我发现didFinishLaunchingWithOptions中的Window对象很快就会发生异常,所以我在屏幕上看不到任何东西。另外我的自定义标签栏控制器对象是零!以下是我的新窗口结构和main.m.任何人都可以告诉我我在哪里做错了?谢谢。iOS:窗口对象为零

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

+0

您是否使用window实例变量将InterfaceBuilder中的“Window”连接起来? – Till 2012-08-04 23:29:59

+0

是的,我按照我所说的 - “引用Appdelegate窗口对象的Window” – applefreak 2012-08-05 09:16:54

回答

2

我得到这个解决......两件事情失踪。

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