代码之家  ›  专栏  ›  技术社区  ›  unsorted

iPhone通过程序初始化选项卡栏控制器视图

  •  0
  • unsorted  · 技术社区  · 14 年前

    我想通过编程来初始化我的标签栏控制器,但是我得到的代码只是一个空白屏幕。我试着模仿 TheElements sample app 一行行一行的东西看起来是可以比较的,但很明显有些问题。有什么建议吗?

    谢谢。。。

    M.

    #import <UIKit/UIKit.h>
    
    int main(int argc, char *argv[]) {
        NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
        int retVal = UIApplicationMain(argc, argv, nil, @"DubbleWrapAppDelegate");
        [pool release];
        return retVal;
    }
    

    在dubblewrapappdelegate.h中:

    @interface DubbleWrapAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
        UIWindow *window;
        UITabBarController *tabBarController;
    }
    
    @property (nonatomic, retain) IBOutlet UIWindow *window;
    @property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
    
    @end
    

    在dubblewrapappdelegate.m中:

    @implementation DubbleWrapAppDelegate
    
    @synthesize window;
    @synthesize tabBarController;
    
    
    - init {
        if (self = [super init]){
            // initialize to nil
            window = nil;
            tabBarController = nil;
        }
        return self;
    }
    
    - (void)applicationDidFinishLaunching:(UIApplication *)application {
    
        SafeTableViewController *vc1 = [[SafeTableViewController alloc] initWithStyle:UITableViewStylePlain];
        [vc1 setSafeItems:[SafeItem knownSafeItems]]; // Set the list of known SafeItems:
        UINavigationController *nc1;
        nc1 = [[UINavigationController alloc] initWithRootViewController:vc1];
        [vc1 release];
    
    
        BoxXRayTableViewController *vc2 = [[BoxXRayTableViewController alloc] initWithStyle:UITableViewStylePlain];
        UINavigationController *nc2;
        nc2 = [[UINavigationController alloc] initWithRootViewController:vc2];
        [vc2 release];
    
        AboutLibertyViewController *vc3 = [[AboutLibertyViewController alloc] init];
        UINavigationController *nc3;
        nc3 = [[UINavigationController alloc] initWithRootViewController:vc3];
        [vc3 release];
    
        NSArray* controllers = [NSArray arrayWithObjects:nc1, nc2, nc3, nil];
    
        tabBarController = [[UITabBarController alloc] init];
        tabBarController.viewControllers = controllers;
        [controllers release];
    
        // Add the tab bar controller's current view as a subview of the window
        window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
        [window setBackgroundColor:[UIColor redColor]];
        [window addSubview:tabBarController.view];
        [window makeKeyAndVisible];
    
        [nc1 release];
        [nc2 release];
        [nc3 release];
    }
    

    设置plist时,没有引用NIB文件。

    1 回复  |  直到 14 年前
        1
  •  1
  •   Philippe Leybaert    14 年前

    你应该抓住窗口对象。您将其标记为自动释放,因此在下一个应用程序循环中释放它。

    不调用自动释放 窗口 :

    window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];