簡體   English   中英

如何將UIButton連接到標簽欄控制器中的特定標簽?

[英]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.

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