![](/img/trans.png)
[英]iPhone tabBar - How should I implement a Modal view so that each time a tab is selected it appears?
[英]How to changed the selected tab items in the Tabbar in iphone?
我已經在視圖控制器中以編程方式創建了標簽欄。 在我的應用程序中,最初顯示了選項卡欄,並且視圖中有五個選項卡欄項目。使用選項卡欄,最初選擇了第一個選項卡項目。 現在我想更改選定的項目,例如,最初選擇了第四項。(查看圖片)
我該如何實現?
這是我的代碼
tBar = [[UITabBarController alloc] init];
first = [[first alloc] initWithNibName:@"first" bundle:nil];
UINavigationController *navFirst = [[[UINavigationController alloc] initWithRootViewController:first] autorelease];
second = [[second alloc] initWithNibName:@"second" bundle:nil];
UINavigationController *navsecond = [[[UINavigationController alloc] initWithRootViewController:second] autorelease];
third = [[third alloc] initWithNibName:@"third" bundle:nil];
UINavigationController *navthird = [[[UINavigationController alloc] initWithRootViewController:third] autorelease];
fourth = [[fourth alloc] initWithNibName:@"fourth" bundle:nil];
UINavigationController *navfourth = [[[UINavigationController alloc] initWithRootViewController:fourth] autorelease];
fifth = [[fifth alloc] initWithNibName:@"fifth" bundle:nil];
UINavigationController *navfifth= [[[UINavigationController alloc] initWithRootViewController:fifth] autorelease];
tBar.viewControllers = [NSArray arrayWithObjects:navFirst,navsecond, navthird, navfourth, navfifth,nil];
[self.view addSubview:tBar.view];
[self.navigationController pushViewController:tBar animated:NO];
參見下圖。 我想要這樣
圖片http://www.freeimagehosting.net/uploads/2798661c55.png
請指導我。
謝謝。
嘗試這個:
YourAppNameDelegate *appDelegate = (YourAppNameDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate tabBarController].selectedIndex = 3;
要么
tBar.selectedIndex = 3;
如果您想以編程方式從一個項目更改為另一個項目,也可以執行以下操作:
[self parentViewController].yourTabBar.selectedIndex = 3;
我希望這可以幫助別人
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.