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. 在項目的目標設置中,將主界面設置爲新創建的窗口。