2012-05-04 34 views
-1

美好的一天。我尝试添加新的导航控制器选项卡到我的应用程序。我创建了一个新的选项卡式应用程序(的Xcode 4.2)和的appdelegate写这将导航控制器添加到选项卡式应用程序

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; 
    // Override point for customization after application launch. 
    UIViewController *viewController1 = [[[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil] autorelease]; 
    UIViewController *viewController2 = [[[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil] autorelease]; 
    NavController *navController = [[[NavController alloc] initWithNibName:@"NavController" bundle:nil] autorelease]; //my controller 
    self.tabBarController = [[[UITabBarController alloc] init] autorelease]; 
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, navController, nil]; 
    self.window.rootViewController = self.tabBarController; 
    [self.window makeKeyAndVisible]; 
    return YES; 
} 

NavController.h文件

@interface NavController : UINavigationController 

@end 

以下项目 Structure of progect

的结构,当我运行它的项目给我看空标签 result 但是在xib文件中我加了标签和按钮 What I want in result 可能是我忘记了什么?

回答

0

初始化您的导航控制器与一些的UIViewController是:

RootViewController *rootViewController = [[[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil] autorelease]; 
    NavController *navController = [[[NavController alloc] initWithRootViewController: rootViewController] autorelease]; 

这可能会有帮助。

0

我正在分享你关于这个功能我的应用程序代码,希望这能解决你的问题很容易

在AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 

    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; 
    self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease]; 

    UINavigationController *localNavigationController; 

    tabBarController = [[UITabBarController alloc] init]; 

    NSMutableArray *localControllersArray = [[NSMutableArray alloc] initWithCapacity:3]; 

    viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease]; 
    localNavigationController = [[UINavigationController alloc] initWithRootViewController:viewController]; 
    [localControllersArray addObject:localNavigationController]; 

    AlaramClock *aAlaramClock = [[[AlaramClock alloc] initWithNibName:@"AlaramClock" bundle:nil] autorelease]; 
    localNavigationController = [[UINavigationController alloc] initWithRootViewController:aAlaramClock]; 
    [localControllersArray addObject:localNavigationController]; 


    CurrentTime *aCurrentTime = [[[CurrentTime alloc] initWithNibName:@"CurrentTime" bundle:nil] autorelease]; 
    localNavigationController = [[UINavigationController alloc] initWithRootViewController:aCurrentTime]; 
    [localControllersArray addObject:localNavigationController]; 

    Settings *aSettings = [[[Settings alloc] initWithNibName:@"Settings" bundle:nil] autorelease]; 
    localNavigationController = [[UINavigationController alloc] initWithRootViewController:aSettings]; 
    [localControllersArray addObject:localNavigationController]; 



    tabBarController.viewControllers = localControllersArray; 

    [localControllersArray release]; 


    // Override point for customization after app launch  
    [window addSubview:tabBarController.view]; 
    [window makeKeyAndVisible]; 

    return YES; 
} 

然后添加以下代码U将得到这个看起来

enter image description here

此后在Every ViewController.m中

添加这个

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) 
    { 
     // Custom initialization 
     [email protected]"Calculate Time"; 
     self.tabBarItem.title = @"Calculate Time"; 
     self.tabBarItem.image=[UIImage imageNamed:@"time_calculate.png"]; 
    } 

    return self; 

} 
+0

试图在委托中添加这个UINavigationController * localNavigationController; NavController * navController = [[[NavController alloc] initWithNibName:@“NavController”bundle:nil] autorelease]; localNavigationController = [[UINavigationController alloc] initWithRootViewController:navController];但它在initWithRootControllerMethod中崩溃 – nabiullinas

相关问题