选项卡栏确实选择委托方法在 ios、swift 3 中给出了先前选择的选项卡索引 [英] tab bar did select delegate methods give the previously selected tab index in ios, swift 3

查看:19
本文介绍了选项卡栏确实选择委托方法在 ios、swift 3 中给出了先前选择的选项卡索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实时检测用户选择了哪个选项卡.例如,如果用户选择 0 th 索引,同时我想让该用户选择了 zeroth 索引选项卡.所以为此,我使用了 tabbarcontroller 委托方法,如下所示.

I'm trying to detect which tab selected by the user, realtime. as an example, if user selecte 0 th index, at the same time I want to get that user has selected the zeroth index tab. so for that , I used tabbarcontroller delegate method like below.

override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {

        print("the selected index is : \(selectedIndex)")
    }

但是这显示了以前的视图控制器.作为一个例子,我认为我在 second tab 然后我选择了 first tab 然后这将索引打印为 2.so 如何获得正确的选定选项卡.希望您对此有所帮助.

but this shows the previous view controller.as an example think I'm in second tab and then I select the first tab then this prints the index as 2.so how can I get the correct selected tab. hope your help with this.

推荐答案

您可以通过从 UITabBarUITabBarItem 的索引>.试试这个

You can get index of selected UITabBarItem by getting position of that particular item from array of items in UITabBar. Try this out

override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
    print("the selected index is : \(tabBar.items.index(of: item))")
}

这篇关于选项卡栏确实选择委托方法在 ios、swift 3 中给出了先前选择的选项卡索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆