簡體   English   中英

如何在選項卡選擇更改視圖時以編程方式檢測(egibaction)?

[英]How can I detect programmatically (e.g.IBAction) when the tab selection changes views?

我正在使用 Swift 5。我希望能夠以編程方式檢測何時單擊選項卡欄項以選擇不同的 ViewController。 理想的情況是能夠為選項卡項選擇設置 IBAction 事件。 雖然我可以為標簽欄項目建立一個出口,但我似乎無法找到為該項目設置 IBAction 的方法。 有沒有辦法做到這一點?

將 UITabBarControllerDelegate 添加到您的 tabBarViewContriller 然后使用此功能。

func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {

    print("last selected index = \(lastSelectedIndex)") //show last index
    print("selected index = \(selectedIndex)") //show current selection index
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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