簡體   English   中英

如何在選項卡欄項目上輕按以方式顯示View Controller

[英]How to modally present a View Controller on tap of tab bar item

我在情節提要中創建了一個帶有3個欄項目的選項卡欄視圖控制器。

現在點擊選項卡欄項,我想展示一個ViewController,它通過導航控制器連接到選項卡欄項。

由於尚未創建任何選項卡欄對象,因此如何以編程方式實現此目的。

(或)是否有一種方法可以捕獲選項卡欄項的選擇(在情節提要中創建)

謝謝...

使用UITabBarControllerDelegate可獲得有關選擇哪個選項卡的通知。

將其添加到viewDidLoad:中,以將視圖控制器分配給每個按鈕:

self.tabBarController.viewControllers = 
 @[firstViewController,secondViewController,thirdViewController];

這是檢測按鈕輕擊的方法:

-(void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    if (tabBarController.selectedIndex == 0) {
       // present your first view controller
    }
    else if (tabBarController.selectedIndex == 1) {
      // present your second view controller
    }
    else if (tabBarController.selectedIndex == 2) {
      // present your third view controller
    }
}

暫無
暫無

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

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