1

即時通訊編程方式做一個UITabBarController在每個UIViewController內使用UINavigationController調用標籤...嘗試了一切...閱讀每篇文章...但100%的教程發現使用UITableViewControllers ...這裏是應用程序的委託:TabBarController和NavigationController的問題

// 
// mluThunderCamAppDelegate.m 
// mluThunderCam 
// 
// Created by Paulo Ferreira on 11/9/09. 
// Copyright MobileLifeUtils.com 2009. All rights reserved. 
// 

#import "mluThunderCamAppDelegate.h" 

@implementation mluThunderCamAppDelegate 

@synthesize window, tbcMain; 


- (void)applicationDidFinishLaunching:(UIApplication *)application {  
    // Override point for customization after application launch 
UINavigationController *ncLocal; 
mluThunderCam *vcThunderCam = [[mluThunderCam alloc] init]; 
ncLocal = [[UINavigationController alloc] initWithRootViewController:vcThunderCam]; 
[ncLocal release]; 

mluThunderCamPreferences *vcThunderCamPreferences = [[mluThunderCamPreferences alloc] init]; 
ncLocal = [[UINavigationController alloc] initWithRootViewController:vcThunderCamPreferences]; 
[ncLocal release]; 

NSArray *aViewControllers = [[NSArray alloc] initWithObjects:vcThunderCam, vcThunderCamPreferences, nil]; 
[vcThunderCam release]; 
[vcThunderCamPreferences release]; 

tbcMain = [[UITabBarController alloc] init]; 

tbcMain.viewControllers = aViewControllers; 

[aViewControllers release]; 

    [window addSubview:tbcMain.view]; 
[window makeKeyAndVisible]; 
} 


- (void)dealloc { 
    [window release]; 
    [super dealloc]; 
} 


@end 

,我想有視圖控制器的結構顯示的導航欄:

// 
// mluThunderCam.m 
// mluThunderCam 
// 
// Created by Paulo Ferreira on 11/10/09. 
// Copyright 2009 MobileLifeUtils.com. All rights reserved. 
// 

#import "mluThunderCam.h" 


@implementation mluThunderCam 

-(id) init { 
self.title = @"Home"; 
self.navigationItem.title = @"Damn!"; 
return self; 
} 

/* 
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad. 
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { 
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) { 
     // Custom initialization 
    } 
    return self; 
} 
*/ 

// Implement loadView to create a view hierarchy programmatically, without using a nib. 
- (void)loadView { 
UIView *vwThunderCam = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]]; 
self.view = vwThunderCam; 
} 

/* 
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. 
- (void)viewDidLoad { 
    [super viewDidLoad]; 
} 
*/ 

/* 
// Override to allow orientations other than the default portrait orientation. 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    // Return YES for supported orientations 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 
*/ 

- (void)didReceiveMemoryWarning { 
// Releases the view if it doesn't have a superview. 
    [super didReceiveMemoryWarning]; 

// Release any cached data, images, etc that aren't in use. 
} 

- (void)viewDidUnload { 
// Release any retained subviews of the main view. 
// e.g. self.myOutlet = nil; 
} 


- (void)dealloc { 
    [super dealloc]; 
} 


@end 

我在做什麼錯?我知道如何使用IB來做到這一點,但是這一次我需要以編程的方式來完成它......先謝謝了!

+0

它開始用大寫字母共同Objective-C的實踐來命名類。 mluThunderCam => MLUThunderCam – coneybeare 2009-11-11 14:39:00

回答

6

您的兩個UINavigationController應該是UITabBarController的viewControllers。他們將顯示您分配給他們的rootViewController。

的結構應該是這樣的:

UITabBarController 
     | 
     |____ UINavigationController 
     |    | 
     |   YourViewController 
     | 
     |____ UINavigationController 
     |    | 
     ...   AnotherViewController 

所以,你的代碼應該是:

- (void)applicationDidFinishLaunching:(UIApplication *)application {  
    // Override point for customization after application launch 

    mluThunderCam *vcThunderCam = [[mluThunderCam alloc] init]; 
    UINavigationController *nav1; = [[UINavigationController alloc] initWithRootViewController:vcThunderCam]; 
    [vcThunderCam release]; 

    mluThunderCamPreferences *vcThunderCamPreferences = [[mluThunderCamPreferences alloc] init]; 
    UINavigationController *nav2; = [[UINavigationController alloc] initWithRootViewController:vcThunderCamPreferences]; 
    [vcThunderCamPreferences release]; 

    NSArray *aViewControllers = [[NSArray alloc] initWithObjects:nav1, nav2, nil]; 
    [nav1 release]; 
    [nav2 release]; 

    tbcMain = [[UITabBarController alloc] init]; 
    tbcMain.viewControllers = aViewControllers; 
    [aViewControllers release]; 

    [window addSubview:tbcMain.view]; 
    [window makeKeyAndVisible]; 
} 
相關問題