更改TABBAR选择的索引
查看更新时,我需要更改tabar选定的项目。因此,我有带4个项目的Tabbar,我希望在单击最后一个索引中的按钮时,查看更新和选定的项目也是最后一个(3)。但是,当我单击按钮时,所选项目会更改,并显示FirstViewController。 需要
let tabBarVC = UIStoryboard(name: "TabBarViewController", bundle: nil).instantiateViewController(withIdentifier: "CustomTabBarViewController")
let nav = UINavigationController(rootViewController: tabBarVC)
nav.setAsRoot()
当我将选定的项目设置为fustantabbarviewController
's viewDidload
还可以,但是我需要,当单击按钮时,我需要,我 当塔巴尔显示时。
I need to change tabbar selected item when view updates. So, i have tabbar with 4 items, i want that when clicking on the button that is in the last index, view updates and selected item also stays the last(3). But when i am clicking on the button, the selected item changes and it shows firstviewcontroller. I am using this code in button click
let tabBarVC = UIStoryboard(name: "TabBarViewController", bundle: nil).instantiateViewController(withIdentifier: "CustomTabBarViewController")
let nav = UINavigationController(rootViewController: tabBarVC)
nav.setAsRoot()
When i set selected item to 3 in CustomTabBarViewController
's viewDidload
it is okay, but i need that when clicking on button that works not always when tabbar is showing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您需要刷新所有VC,
但是如果您只需要刷新最后一个VC,则
If you need to refresh all the vcs
But if you need to refresh only the last vc then
基本思想是,
tabbarcontroller:syseclectViewController:selector
在您的uitabbarcontroller委托中,每当用户单击选项卡项目时,都会调用。因此,通过适当地定义该方法,您有机会在当前视图控制器被单击选项卡栏中选择的用户替换为当前视图控制器之前进行自己的处理。
因此,只需从此选择器中返回否,以防您希望防止当前视图控制器更换,即当交易正在进行时。
The basic idea is that the
tabBarController:shouldSelectViewController: selector
in your UITabBarController delegate is called whenever the user clicks on tab item.Thus, by appropriately defining that method, you get a chance to do your own processing before the current view controller is replaced by the one the user selected by clicking in the tab bar.
So, simply return NO from this selector in case you wish to prevent the current view controller to be replaced, i.e. when a transaction is ongoing.