2012-05-04 11 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ファイルでlableとボタンを追加する What I want in result 私は何かを忘れているかもしれませんか?

答えて

0

があるいくつかのUIViewControllerであなたのナビゲーションコントローラを初期化:

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

これは役立つかもしれません。

0

私はこの機能についてのあなたに私のAPPのコードを共有しています、これ見てUが取得されます、これは簡単に

が続い

- (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; 
} 

AppDelegate.m

にこのコードを追加し、あなたの問題を解決することを願って

enter image description here

これ以降のすべてのViewController.m

ADDこの

- (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"バンドル:nil] autorelease]; localNavigationController = [[UINavigationController alloc] initWithRootViewController:navController];しかし、initWithRootControllerMethodでクラッシュしました – nabiullinas

関連する問題