2013-03-27 51 views
0

我正在開發一個帶有標籤欄的ios應用程序。我在酒吧上有5個以上的按鈕,所以在iphone上我更多地使用了按鈕。 現在,假設我有這個按鈕:按鈕1按鈕2按鈕3按鈕4更多(和裏面更多)按鈕5按鈕6。 如果我點擊更多,然後Button5我進入相對於Button5的視圖。然後我點擊Button2(這不是更多),我進入相對於Button2的視圖。 目前爲止這麼好。 現在,如果我點擊更多,我不去更多選項卡,但回到相對於Button5的視圖。 我如何讓更多的按鈕始終走向更多的視野?我如何讓更多的按鈕始終更多的視圖?

回答

0

我用這個代碼在我的應用程序delegate.m解決問題

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController { 
    UITabBarController* tabBarController2 = (UITabBarController*)self.window.rootViewController; 
    if (tabBarController2.selectedIndex < 4) { 
     [tabBarController2.moreNavigationController popViewControllerAnimated:NO]; 
    } 
} 
+0

有沒有什麼辦法顯示在標籤欄中的所有六個按鈕,而不是顯示更多的按鈕,其中包含按鈕5和按鈕6 PLZ建議 – UserDeviOS 2013-12-27 11:48:30

0

你可以做的另一種方法是,無論何時用戶按下更多,第一個按鈕被刪除,其他按鈕被添加。 基本上,你可以創建一個數組,並保持其中的所有按鈕。然後基於按下的按鈕,您可以導航到特定的視圖。

對於防爆:

開始您有:Button1Button2Button3Button4Next

單擊下一步之後:PrevButton3Button4Button5Button6

+0

很酷。我想,在目標C方面我並不那麼專業。 ^^' – 2013-03-27 10:11:37

1

你並不需要添加更多按鈕。只需設置視圖控制器到的UITabBarController

- (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated 

,如果你有超過5個視圖控制器會自動創建一個更按鈕!即的NSArray的計數大於5

+0

是的,我知道。問題在於如何點擊按鈕導致始終顯示第五個按鈕後面的按鈕鏈接的更多視圖,而不是顯示在更多視圖中選擇的最後一個視圖^^ – 2013-03-27 10:51:06

+0

標籤欄顯示您的自定義的空間有限項目。如果將六個或更多自定義視圖控制器添加到選項卡欄控制器,則選項卡欄控制器僅顯示前四個項目加上標籤欄上的標準更多項目。點擊更多項目會彈出一個選擇剩餘項目的標準界面。標準更多項目的界面包含一個編輯按鈕,允許用戶重新配置標籤欄。 – 2013-03-27 11:05:22

+0

我實際上沒有得到你想要的東西! 可能會闡述更多? – 2013-03-27 11:06:51

0
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    // Override point for customization after application launch. 
    UIViewController *viewController1 = [[UIViewController alloc] init]; 
    UIViewController *viewController2 = [[UIViewController alloc] init]; 
    UIViewController *viewController3 = [[UIViewController alloc] init]; 
    UIViewController *viewController4 = [[UIViewController alloc] init]; 
    UIViewController *viewController5 = [[UIViewController alloc] init]; 
    UIViewController *viewController6 = [[UIViewController alloc] init]; 
    UIViewController *viewController7 = [[UIViewController alloc] init]; 
    UIViewController *viewController8 = [[UIViewController alloc] init]; 
    UIViewController *viewController9 = [[UIViewController alloc] init]; 

    [viewController1.view setBackgroundColor:[UIColor whiteColor]]; 
    [viewController2.view setBackgroundColor:[UIColor redColor]]; 
    [viewController3.view setBackgroundColor:[UIColor greenColor]]; 
    [viewController4.view setBackgroundColor:[UIColor grayColor]]; 
    [viewController5.view setBackgroundColor:[UIColor blueColor]]; 
    [viewController6.view setBackgroundColor:[UIColor yellowColor]]; 
    [viewController7.view setBackgroundColor:[UIColor brownColor]]; 
    [viewController8.view setBackgroundColor:[UIColor magentaColor]]; 
    [viewController9.view setBackgroundColor:[UIColor purpleColor]]; 

    [viewController1 setTitle:@"one"]; 
    [viewController2 setTitle:@"two"]; 
    [viewController3 setTitle:@"three"]; 
    [viewController4 setTitle:@"four"]; 
    [viewController5 setTitle:@"five"]; 
    [viewController6 setTitle:@"six"]; 
    [viewController7 setTitle:@"seven"]; 
    [viewController8 setTitle:@"eight"]; 
    [viewController9 setTitle:@"nine"]; 

    self.tabBarController = [[UITabBarController alloc] init]; 
    self.tabBarController.viewControllers = @[viewController1, viewController2, viewController3, viewController4, viewController5, viewController6, viewController7, viewController8, viewController9]; 
    self.window.rootViewController = self.tabBarController; 
    [self.window makeKeyAndVisible]; 
    return YES; 
} 

我已經添加了我試圖和樣品的AppDelegate代碼其對我來說工作絕對好。讓我知道你在這有什麼問題。

+0

我發現一個更簡單的解決方案,但這是真棒!非常感謝!對於像我這樣的新手這是純金! – 2013-03-29 10:28:41

相關問題