2015-04-06 46 views
0

我有一個View Controller底部有UITabBar。此選項卡欄根據所選的選項卡執行不同的功能。我想在加載view controller時選擇其中一個按鈕。我無法找到不涉及的解決方案tabbarviewcontroller無法在視圖控制器中的標籤欄上設置默認按鈕

+0

你的問題還不清楚,請詳細說明一下。 – 2015-04-06 04:51:26

回答

0
class ViewController: UIViewController, UITabBarDelegate { 
@IBOutlet var tabBar : UITabBar 
//In view controller declare a UITabBar as an Outlet 
override func viewDidLoad() { 
    super.viewDidLoad() 
    tabBar.selectedItem = tabBar.items[0] as UITabBarItem;// here you 
    can load the default button option which you want to load        
} 
func tabBar(tabBar: UITabBar!, didSelectItem item: UITabBarItem!) { 
    var tabBarValue = 0; 
    switch item.tag { 
    case 0: 
     tabBarValue = // assign value 
     break 
    case 1: 
     tabBarValue = // assign value 
     break 
    default: 
     break 
    }} 

P1。請參考下面的網址,他們嘗試爲選定的標籤加載不同的網頁視圖,Use a UITabBar without UITabBarController to control a UIWebView

+0

由於某種原因,這不是我的工作。但是,我確實找到了另一種方式。 – Ryguyu 2015-04-11 19:07:34

0

這是爲我制定的解決方案。

for i in tabBar.items as [UITabBarItem] { 
     if i.tag == 0 { 
      tabBar.selectedItem = i 
     } 
相關問題