如何设置视图的标签栏?

发布于 2024-12-02 02:05:17 字数 1780 浏览 2 评论 0原文

我有一个视图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];

}

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

}

}

提前致谢...

I have a view1 and view2. In view1 i have set a dynamically tab-bar with two tab-bar items. Now i want to set on view1, that is in which i have add tab bar, at first tab bar item. And on second tab-bar item i want to set view2. Now tell me how set view1 on first tab bar item so that when user click on tab bar item1 then display view1 again with same data?
How do that? i use this code for tab bar

 - (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];

}

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

}

}

Thanks in advance...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

み青杉依旧 2024-12-09 02:05:17

我想您可以使用 Tabbar 应用程序模板创建一个新项目,这比您自己实现它更容易并且工作完美。

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

I guess you can just create a new project using the Tabbar application template, thats way easier than implementing it yourself and works perfectly.

If you want the tabbar inside of a subview or modal view, or just not in the main view then thats almost easier. In the view were you want the tabbar drag and drop a tabbar controller into the xib. Set your views for the individual tabs (still in IB) and to let the tabbarcontroller appear, simply create an IBOutlet and connect it to your tabbarcontroller and add it as superview when you want it to appear: [self.view addSubview:tabbarController]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文