Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/100.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 带有NavigationBar的TabBar应用程序_Ios_Uinavigationcontroller_Uitabbarcontroller - Fatal编程技术网

Ios 带有NavigationBar的TabBar应用程序

Ios 带有NavigationBar的TabBar应用程序,ios,uinavigationcontroller,uitabbarcontroller,Ios,Uinavigationcontroller,Uitabbarcontroller,我正在构建一个基于TabBar的应用程序。其中一个选项卡将显示一个TableView,我希望顶部有一个导航栏 然而,我需要将此应用程序中的所有内容本地化为几种语言,因此需要在代码中完成 我在AppDelegate中设置了选项卡栏 @implementation AppDelegate @synthesize window = _window; @synthesize tabBarController = _tabBarController; - (BOOL)application:(UI

我正在构建一个基于TabBar的应用程序。其中一个选项卡将显示一个TableView,我希望顶部有一个导航栏

然而,我需要将此应用程序中的所有内容本地化为几种语言,因此需要在代码中完成

我在AppDelegate中设置了选项卡栏

@implementation AppDelegate

@synthesize window = _window;
@synthesize tabBarController = _tabBarController;



- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    UIViewController *viewController1 = [[HomeViewController alloc] initWithNibName:@"HomeView" bundle:nil];
    UIViewController *viewController2 = [[RecycleViewController alloc] initWithNibName:@"RecycleView" bundle:nil];
    UIViewController *viewController3 = [[SettingsViewController alloc] initWithNibName:@"SettingsView" bundle:nil];
    UIViewController *viewController4 = [[SettingsViewController alloc] initWithNibName:@"SettingsView" bundle:nil];

    self.tabBarController = [[UITabBarController alloc] init];
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2,viewController3, viewController4, nil];
    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];
    return YES;
}
每个窗口都有选项卡上信息的代码

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.title = NSLocalizedString(@"Home", @"Home");
        self.tabBarItem.image = [UIImage imageNamed:@"home"];
    }
    return self;
}
到目前为止还不错,但是RecyclingView(TableView)需要一个导航栏,我可以在这里使用NSLocalizedString设置标题


我非常感谢您的帮助。

您可以使用Interface Builder对XIB进行本地化,这样您就不必通过编程实现


您可以使用Interface Builder对XIB进行本地化,这样就不必通过编程来实现


您需要在
选项卡控制器的
视图控制器的第二个索引处添加
UINavigationController
,而不是添加视图控制器-

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    UIViewController *viewController1 = [[HomeViewController alloc] initWithNibName:@"HomeView" bundle:nil];
    UIViewController *viewController2 = [[RecycleViewController alloc] initWithNibName:@"RecycleView" bundle:nil];
    UIViewController *viewController3 = [[SettingsViewController alloc] initWithNibName:@"SettingsView" bundle:nil];
    UIViewController *viewController4 = [[SettingsViewController alloc] initWithNibName:@"SettingsView" bundle:nil];

    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController2];

    self.tabBarController = [[UITabBarController alloc] init];
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, navController,viewController3, viewController4, nil];
    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];
    return YES;
}
要在导航栏上设置标题,可以将其写入
RecycleViewController
viewDidLoad

[self.navigationItem setTitle:@"title"];

您需要在
tabBarController
viewControllers
的第二个索引处添加
UINavigationController
,而不是添加视图控制器-

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    UIViewController *viewController1 = [[HomeViewController alloc] initWithNibName:@"HomeView" bundle:nil];
    UIViewController *viewController2 = [[RecycleViewController alloc] initWithNibName:@"RecycleView" bundle:nil];
    UIViewController *viewController3 = [[SettingsViewController alloc] initWithNibName:@"SettingsView" bundle:nil];
    UIViewController *viewController4 = [[SettingsViewController alloc] initWithNibName:@"SettingsView" bundle:nil];

    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController2];

    self.tabBarController = [[UITabBarController alloc] init];
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, navController,viewController3, viewController4, nil];
    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];
    return YES;
}
要在导航栏上设置标题,可以将其写入
RecycleViewController
viewDidLoad

[self.navigationItem setTitle:@"title"];

xcode 4.3.2的答案是:

将RecycleViewController.m中的UINavigationBar分配为:

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:self];
self.view addSubview:navController.view;
但是有一个错误,导航栏顶部会显示一个空白,大约10像素

这是另一个解决方案:
使用xib builder,在视图RecycleViewController.xib顶部的库中添加一个导航栏,按ctrl+“导航项”,指向RecycleViewController.h插入一个IBOutlet,然后将显示一个外观良好的导航栏。

xcode 4.3.2的答案是:

将RecycleViewController.m中的UINavigationBar分配为:

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:self];
self.view addSubview:navController.view;
但是有一个错误,导航栏顶部会显示一个空白,大约10像素

这是另一个解决方案: 使用xib生成器,从视图RecycleViewController.xib顶部的库中添加导航栏,按ctrl+“导航项”,指向RecycleViewController.h以插入IBOutlet,然后将显示一个外观良好的导航栏