Iphone 如何设置视图的选项卡栏?

Iphone 如何设置视图的选项卡栏?,iphone,uiviewcontroller,uitabbarcontroller,uitabbar,Iphone,Uiviewcontroller,Uitabbarcontroller,Uitabbar,我有一个视图1和视图2。在view1中,我设置了一个带有两个选项卡栏项的动态选项卡栏。现在我想在view1上设置,在第一个选项卡栏项中,我在其中添加了选项卡栏。在第二个选项卡栏项上,我要设置view2。现在告诉我如何在第一个选项卡栏项目上设置view1,以便当用户单击选项卡栏项目1时,再次显示具有相同数据的view1? 你怎么知道的?我将此代码用于选项卡栏 - (void)viewDidLoad { self.title = @"Business Details"; CGRect myTab

我有一个视图1和视图2。在view1中,我设置了一个带有两个选项卡栏项的动态选项卡栏。现在我想在view1上设置,在第一个选项卡栏项中,我在其中添加了选项卡栏。在第二个选项卡栏项上,我要设置view2。现在告诉我如何在第一个选项卡栏项目上设置view1,以便当用户单击选项卡栏项目1时,再次显示具有相同数据的view1? 你怎么知道的?我将此代码用于选项卡栏

 - (void)viewDidLoad {

self.title = @"Business Details";
CGRect myTab =CGRectMake(0,368,320,49);
UITabBar *tabBar = [[[UITabBar alloc] initWithFrame:myTab] autorelease];
NSMutableArray *items = [[[NSMutableArray alloc] init] autorelease];

// Add a 'contacts' item 
[items addObject:[[[UITabBarItem alloc] initWithTitle:@"Detail View" image:nil tag:1] autorelease] ];

// Add a 'More' item
[items addObject:[[[UITabBarItem alloc] initWithTitle:@"Review" image:nil tag:2] autorelease] ];


// Put the items in the tab bar
tabBar.items = items;

// Setup this object to respond to tab changes
tabBar.delegate = self;
[self.view addSubview:tabBar];

  [super viewDidLoad];
}

}


提前感谢…

我想您可以使用Tabbar应用程序模板创建一个新项目,这比您自己实现它要容易得多,而且效果非常好


如果希望选项卡栏位于子视图或模态视图中,或者不在主视图中,那么这几乎更容易。在视图中,您希望tabbar将tabbar控制器拖放到xib中。设置各个选项卡的视图(仍在IB中)并让tabbarcontroller显示,只需创建一个IBOutlet并将其连接到tabbarcontroller,并在需要显示时将其添加为superview:
[self.view addSubview:tabbarcontroller]

我想在项目的中间阶段使用它,所以我不能使用新的Tabbar应用程序模板。谢谢你的建议,我会更新帖子,然后希望你能得到答案!
 - (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
switch (item.tag ) {
    case 1:
        dv=[[[DetailView alloc]initWithNibName:@"DetailView" bundle:nil]autorelease];
        [self.navigationController pushViewController:dv animated:YES];
        self.navigationItem.backBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:nil action:nil] autorelease];


        break;
    case 2:
        review_view=[[[Review alloc]initWithNibName:@"Review" bundle:nil]autorelease];
        [self.navigationController pushViewController:review_view animated:YES];
        self.navigationItem.backBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:nil action:nil] autorelease];


    default:
        break;

}