[英]How can I connect a UIButton to a specific tab in my Tab Bar Controller?
我有一個具有2個標簽的UITabBarController
。 每個標簽都不同,但是都可以在頂部發布新帖子。 當我點擊任一視圖上的新post
按鈕時,我將看到相同的ViewController
Modally。 如果我按下了“ cancel
按鈕,則將其關閉,然后返回正確的選項卡,沒有問題。 但是,如果我按下了post
按鈕,則希望它始終顯示在第一個選項卡上。
如何以編程方式告訴它切換到第一個標簽
self.dismissViewControllerAnimated(true, completion: nil)
這是我的情節提要
這是我點擊發布按鈕時調用的代碼:
@IBAction func accept(sender: AnyObject) {
var currentUserLocation = getUserLocation()
currentUserLocation.getUserCoordinates()
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
var tabBarController = appDelegate.window!.rootViewController as! UITabBarController
tabBarController.SelectedIndex = 0
self.dismissViewControllerAnimated(true, completion: nil)
}
我最終遇到了錯誤:
'UITabBarController' does not have a member named 'SelectedIndex'
具有以下內容:
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
var tabBarController = appDelegate.window!.rootViewController as! UITabBarController
tabBarController.selectedIndex = 0
索引為0的控制器對應於最左邊的選項卡,索引為1的控制器對應於最右邊的下一個選項卡,依此類推。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.