Objective c 如何在视图控制器(而非应用程序内委托)中创建选项卡栏控制器?IOS 4.1

Objective c 如何在视图控制器(而非应用程序内委托)中创建选项卡栏控制器?IOS 4.1,objective-c,ios,uitabbarcontroller,Objective C,Ios,Uitabbarcontroller,我正在创建一个tab bar应用程序,但我想使用interface builder在Main.xib中创建tab bar控制器。因为我的应用程序没有Main.Xib。因此,我应该在ViewController.xib中或在controller/appdelegate中以编程方式执行此操作。我找不到任何好的教程或例子 在我的应用程序中,我有 AppDelegate.h AppDelegate.m ViewController.h ViewController.m ViewController.xi

我正在创建一个tab bar应用程序,但我想使用interface builder在Main.xib中创建tab bar控制器。因为我的应用程序没有Main.Xib。因此,我应该在ViewController.xib中或在controller/appdelegate中以编程方式执行此操作。我找不到任何好的教程或例子

在我的应用程序中,我有

AppDelegate.h
AppDelegate.m
ViewController.h
ViewController.m
ViewController.xib
我的应用程序从ViewController的视图开始。xib我知道我不想添加选项卡栏,而是要添加一个选项卡栏控制器,它将始终位于视图的底部。我该怎么做

阿帕德拉盖特

- (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;
}
我试着用程序化的方法去做,但是我想不出来


提前感谢您提供的示例代码

这将创建一个包含3个视图的选项卡栏

self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:view1, view2, view2, nil];
self.window.rootViewController = self.tabBarController;
我发现这很有效 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;

///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;

您可以通过单击按钮在ViewController中加载tabbar控制器,或者您想要什么?默认情况下,当应用程序完成启动时,它应该像常规的选项卡栏控制器一样保持在那里
self.rootController=[[UITabBarController alloc]init];ViewController*view1=[[ViewController alloc]init];self.rootController.viewControllers=[NSArray arrayWithObjects:view1 nil]给出错误“调用的对象类型``ViewController'不是函数或函数指针ViewController是什么?你自定义创建了这个吗?是的,当你应用代码时,xcode需要定义view1、vie2等。我查看了appledeveloper文档,view1应该使用target viewcotnroller定义。我想你最好看看Apple提供的示例代码。