如何使用UITabBarController的shouldSelectViewController委托方法
我有一个基于选项卡栏的应用程序(选项卡栏控制器添加在窗口本身中),并且所有导航控制器及其各自的根视图控制器都在窗口的 xib 中设置。我有 4 个选项卡栏项目。
假设我单击第 1 项,则将向我显示该项目的根视图控制器。该根视图包含一个包含 5 个单元格的表。如果我单击一行,则会将一个新视图推送到导航堆栈上。现在,这个推送的视图有一个按钮,单击该按钮将再次推送一个新的视图控制器。我有 4 个这样的视图控制器,它们被一个接一个地推送到导航堆栈上。
现在,假设我位于导航堆栈中的第三个视图,然后,我单击了选项卡栏项目 1(与我之前单击的相同);然后,显示第一个根视图控制器,我的整个导航堆栈消失了。我只是不想发生这种情况,也就是说,我想保留在第三个视图控制器上,并且能够单击所有选项卡栏项目(不想禁用任何项目)。我知道它可以通过实现选项卡栏控制器委托方法来实现:shouldSelectViewController,但我不知道如何实现?
I have a tabbar-based application (tabbar controller is added in window itself) and all the navigation controller with their respective root view controllers are being set in window's xib. I have 4 tab bar items.
Suppose I click on item 1, then the root view controller for that item is being shown to me. This root view contains a table with 5 cells. If I click on a row, then a new view is pushed onto the navigation stack. Now, this pushed view has a button clicking on which will again push a new view controller. I have 4 such view controllers which are getting pushed one after the other on navigation stack.
Now, lets say I am on 3rd view in navigation stack and then, I have clicked on tab bar item 1 (the same on which I clicked earlier); then, the first root view controller is shown and my whole navigation stack is gone. I just don't want this to happen, that is, I want to remain on the 3rd view controller and also, be able to click on all tab bar items (dont want to disable any item). I know that it can be achieved through implementing tab bar controllers delegate method: shouldSelectViewController, but i dont know how??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对当前选定的视图控制器执行检查。
如果当前与点击的选项卡相同,则在委托方法中返回 no 。你认为这样的事情就是你的意思吗?
perform a check for the currently selected viewcontroller.
if current is the same as the tab tapped, then return no in your delegate method. Think something like this is what you mean?