我的View Controller
底部有一个UITabBar
。此选项卡栏根据选择的选项卡执行不同的功能。我想在view controller
加载时选择其中一个按钮。我无法找到一个不涉及tabbarviewcontroller
答案 0 :(得分: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
}}
PL。请参阅以下网址,他们尝试为所选标签加载不同的网页浏览Use a UITabBar without UITabBarController to control a UIWebView
答案 1 :(得分:0)
这是我的解决方案。
for i in tabBar.items as [UITabBarItem] {
if i.tag == 0 {
tabBar.selectedItem = i
}