簡體   English   中英

更改UITabBarController中的選項卡順序

[英]Change the order of tabs in UITabBarController

目前,我正在開發一個包含3個選項卡的選項卡式應用程序,我想知道是否可以更改選項卡的順序,即將第三個選項卡放在第一個選項卡的位置?

只需在情節提要中進行更改即可。 修改XML這樣的小東西很容易。 在您選擇的編輯器中打開Storyboard文件,然后搜索“ tabBarController”。 您會發現以下內容:

<connections> <segue destination="XmF-SX-cO9" kind="relationship" relationship="viewControllers" id="CZB-Ec-d55"/> <segue destination="mCx-nD-74Q" kind="relationship" relationship="viewControllers" id="3PE-EG-9Vs"/> <segue destination="bxy-1d-KHG" kind="relationship" relationship="viewControllers" id="OP9-xt-ZMo"/> <segue destination="JqF-xj-sCJ" kind="relationship" relationship="viewControllers" id="cHB-MZ-3bs"/> </connections>

這代表了選項卡的當前順序。 如果要切換第一個和第二個選項卡,只需切換它們在此列表中的位置。 就這么簡單。

嘗試這個:

UITabBarController *tabController;
NSArray *controllers = tabController.viewControllers;
NSArray *reorderedControllers = [controllers sortedArrayUsingComparator:yourComparator];
[tabController setViewControllers:reorderedControllers];

通過屬性從選項卡中獲取當前viewControllers

NSArray *viewControllers = myTabBarController.viewControllers;

然后手動將數組中的viewController重新排序:

NSArray *newOrderedViewController = [NSArray arrayWithObjects:viewControllers[2],viewControllers[0],viewControllers[1],viewControllers[3], nil];

最后設置新的順序視圖控制器。

myTabBarController.viewControllers = newOrderedViewController;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM