Iphone 在应用程序代理中添加导航栏

Iphone 在应用程序代理中添加导航栏,iphone,objective-c,ios,xcode,Iphone,Objective C,Ios,Xcode,我的appdelegate有问题。我想添加一个导航栏,但它不起作用 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.tabBarContro

我的appdelegate有问题。我想添加一个导航栏,但它不起作用

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    self.tabBarController = [[UITabBarController alloc] init];

    UniversViewController *universViewController = [[UniversViewController alloc] initWithNibName:@"ProduitsListinTableViewController" bundle:nil];
    universViewController.title = @"univers";

    CategoriesViewController *categoriesViewController = [[CategoriesViewController alloc] initWithNibName:@"ProduitsListinTableViewController" bundle:nil];
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:categoriesViewController];
    navigationController.title = @"categories";
    [navigationController setNavigationBarHidden:NO];

    ProduitsListinTableViewController *produitListe = [[ProduitsListinTableViewController alloc] initWithNibName:@"ProduitsListinTableViewController" bundle:nil];
    produitListe.title = @"troisième";

    _tabBarController.viewControllers = [NSArray arrayWithObjects:universViewController, categoriesViewController, produitListe, nil];

    [self.window setRootViewController:_tabBarController];
    [self.window makeKeyAndVisible];

    return YES;
}

我必须在
universeviewcontroller
CategoriesViewController
produitslistinetableviewcontroller
中添加一些内容吗?还是直接在appdelegate中添加这些内容?

当我同时拥有UINavigationController和UIAbbarController时,我总是采用这种方法:
您需要从基于视图的应用程序开始。然后在appDelegate文件中创建UITabbarController

Appdelegate.h

UITabBarController *tabBarController;
// set properties

Appdelegate.m

// Synthesize

tabBarController = [[UITabBarController alloc] init];
tabBarController.delegate=self;

// Adding Search,Nearby,Map,AboutUs,Favorites Tabs to tabBarController  
Search * search = [[Search alloc] init];  
UINavigationController *searchNav = [[UINavigationController alloc]        initWithRootViewController:search];  

Nearby* nearby = [[Nearby alloc] init];  
UINavigationController *nearbyNav = [[UINavigationController alloc] initWithRootViewController:nearby];  

Map* map = [[Map alloc] init];  
UINavigationController *mapNav = [[UINavigationController alloc] initWithRootViewController:map];  

AboutUs* aboutUs = [[AboutUs alloc] init];  
UINavigationController *aboutUsNav = [[UINavigationController alloc] initWithRootViewController:aboutUs];  

Favorites* favorites = [[Favorites alloc] init];  
UINavigationController *favoritesNav = [[UINavigationController alloc] initWithRootViewController:favorites];  

NSArray* controllers = [NSArray arrayWithObjects:searchNav,nearbyNav,mapNav,aboutUsNav,favoritesNav, nil];  
tabBarController.viewControllers = controllers; 

[window addSubview:tabBarController.view];    
您可以相应地管理要将导航控制器或仅视图控制器放置在哪个选项卡中

然后在上面提到的每个视图控制器中,您需要实现

- (id)init {}
您可以在其中设置选项卡名称和图像


我总是遵循这种方法,而且从未失败过。选项卡始终可见。您可以根据代码进行更改。

尝试以下代码:

- (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, *viewController2,*viewController3,*viewController4,*viewController5;

    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
    {

        viewController1 = [[[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil] autorelease];

        navController=[[UINavigationController alloc] initWithRootViewController:viewController1];

        viewController2 = [[[SearchViewController alloc] initWithNibName:@"SearchViewController" bundle:nil] autorelease];

        navController2=[[UINavigationController alloc] initWithRootViewController:viewController2];

        viewController3 = [[[LocationsViewController alloc] initWithNibName:@"LocationsViewController" bundle:nil] autorelease];

        navController3=[[UINavigationController alloc] initWithRootViewController:viewController3];

        viewController4 = [[[CallViewController alloc] initWithNibName:@"CallViewController" bundle:nil] autorelease];

        navController4=[[UINavigationController alloc] initWithRootViewController:viewController4];

        viewController5 = [[[MyBookingsViewController alloc] initWithNibName:@"MyBookingsViewController" bundle:nil] autorelease];

        navController5=[[UINavigationController alloc] initWithRootViewController:viewController5];


    }

    self.tabBarController = [[[UITabBarController alloc] init] autorelease];

    self.tabBarController.viewControllers = [NSArray arrayWithObjects:navController,navController2,navController3,navController4,navController5,nil];

    //self.window.rootViewController =self.navController;

    self.window.rootViewController=self.tabBarController;

    [self.window makeKeyAndVisible];

    return YES;
}

嗨,谢谢你,这是完美的,它的工作!我添加了viewController1.title=@“title”;因此标题直接出现。再次感谢你!嗨,谢谢你的留言。我试过了,但没用。我想我做错了什么。。但这篇博文对我很有用。