0

我正在创建一个标签栏应用程序,但我想通过使用界面生成器创建不在 Main.xib 中的标签栏控制器。因为我的应用没有 Main.Xib。所以我要么应该在 ViewController.xib 中进行,要么在控制器/appdelegate 中以编程方式进行。我找不到任何好的教程或示例。

在我的应用程序中,我有

AppDelegate.h
AppDelegate.m
ViewController.h
ViewController.m
ViewController.xib

我的应用程序从 ViewController.xib 的视图开始,我知道我想添加的不是标签栏,而是一个标签栏控制器,它将始终保持在视图的底部。我怎样才能做到这一点?

appdelagete.h

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

    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
    self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];

    return YES;
}

我试图通过查看苹果开发人员文档以编程方式进行操作,但无法弄清楚。

提前感谢任何示例代码

4

3 回答 3

1

我发现这很好用 appdelegate.h

@property (nonatomic, retain) UITabBarController *rootController

appdelegate.m

UIViewController *viewController1 = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
self.rootController = [[[UITabBarController alloc] init] autorelease];
self.rootController.viewControllers = [NSArray arrayWithObjects:viewController1, nil];
self.window.rootViewController = self.rootController;
于 2012-06-20T23:06:49.977 回答
0

This will create a tab bar with 3 views

self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:view1, view2, view2, nil];
self.window.rootViewController = self.tabBarController;
于 2012-06-19T02:58:30.850 回答
0

///AppDelegate.m 文件:didFinishLaunchingWithOptions 方法

//initiate window
window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];

//initiate viewcontrollers
FirstViewController *aFirstViewController = [FirstViewController new];

SecondViewController *aSecondViewController = [SecondViewController new];

 aFirstViewController.tabBarItem.title = @"First";
aFirstViewController.tabBarIte
 aSecondViewController.tabBarItem.title = @"Second";

gTabBarController = [[UITabBarController alloc]init];
gTabBarController.viewControllers = @[aFirstViewController ,aSecondViewController];

//show the main window and also make it key
[window makeKeyAndVisible];


window.rootViewController = gTabBarController;
于 2017-02-04T06:40:43.177 回答