我在我的项目中获得了TabBarController
两个视图。现在我想在应用启动时设置一个FirstViewController
,其中两个按钮为Initial View Controller
。第一个按钮的TabBarController
应显示FirstView
,第二个按钮应显示第二个按钮。当两个按钮中的一个被按下时,FirstViewController
应该消失,并且应该只能在两个视图之间导航,其中TabBarViewController
中的选项卡。按钮显示选项卡
Q
按钮显示选项卡
0
A
回答
0
我做了一些小修改,并测试我写的代码和它的作品。控制从firstButton拖到TabBarController并选择Kind作为“Show”。然后用secondButton做同样的事情。 在与两个按钮你的看法,我首先把它叫做:
import Foundation
import UIKit
class First: UIViewController {
var firstWasClicked = false
@IBAction func firstButtonAction(sender: UIButton) {
firstWasClicked = true
}
@IBAction func secondButtonAction(sender: UIButton) {
firstWasClicked = false
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let controller = segue.destinationViewController as! TabBarController
controller.firstSelected = firstWasClicked
}
}
然后在TabBarController:
import Foundation
import UIKit
class TabBarController: UITabBarController {
var firstSelected = true
override func viewDidLoad() {
if(firstSelected) {
self.selectedIndex = 0
}
else {
self.selectedIndex = 1
}
}
}
0
这可能是你想要的。
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func didTapFirst(button: UIButton) {
showViewControllerAt(index: 0)
}
@IBAction func didTapSecond(button: UIButton) {
showViewControllerAt(index: 1)
}
func showViewControllerAt(index: NSInteger) {
let tabBarController = self.storyboard?.instantiateViewController(withIdentifier: "TabBarController") as! UITabBarController
tabBarController.selectedIndex = index
UIApplication.shared.keyWindow?.rootViewController = tabBarController
}
}
不要忘记设置你的UITabBarController
的Storyboard ID
。
相关问题
- 1. Jira - 项目概览选项卡上不显示版本按钮
- 2. Dynamic CRM 2011.使用单选按钮隐藏/显示选项卡
- 3. jQuery选项卡不按预期显示
- 4. bootstrap 4个嵌套选项卡:'全部显示'按钮以显示子选项卡中的节点
- 5. 选项卡按钮功能
- 6. 按钮的Bootstrap选项卡?
- 7. TabLayoutPanel选项卡按钮单击后不显示
- 8. 在布局模式下显示“选项卡控制按钮”
- 9. 单击键盘选项卡按钮时显示下拉列表
- 10. 在按钮中显示下拉选项
- 11. 显示拆分按钮选项
- 12. 作为选项卡的单选按钮
- 13. 通过单选按钮选项卡
- 14. Jquery显示选项卡
- 15. 按钮不会更改JQuery UI选项卡中的选项卡
- 16. 选项卡显示默认值,需要显示我们选择的选项卡
- 17. 如何使按钮显示其他按钮和选项。
- 18. Android选项卡,如何显示选定选项卡的图像
- 19. 按大小写显示项目(复选框,单选按钮等...)
- 20. Eclipse样式的选项卡式窗格 - “显示列表”按钮太多时选项卡
- 21. 显示按钮被选中
- 22. 单选按钮不显示
- 23. 显示选中的按钮
- 24. jQuery选项卡:按索引设置选项卡导航按钮的css
- 25. Visual Studio 2010选项卡关闭按钮
- 26. TabControl选项卡按钮位置
- 27. 切换选项卡中的按钮
- 28. ADO访问选项卡按钮
- 29. wxFrame不处理选项卡按钮
- 30. 选项卡和图像视图按钮
您的意思是选项卡,而不是点击。 – rmaddy
您是否正在使用TabBarController来满足上述要求? – Vinodh
什么是更好的解决方案? –