swift ios9:如果已选中选项卡,请在单击时将当前选项卡切换到另一个选项卡

时间:2022-10-13 21:15:54

Ok so here is the thing, i have an app with a tabbarcontroller. I have four tabs on this tabbarcontroller (test1, test3, test4, test5). If i am already on the first tab, when i select it, i want this tab to change from test1 to test2. Currently i managed to change the title, but for actually reload the view i have to switch to one of the other tabs and come back. I'm struggling on this issue for quite a while now and i can't seem to find where i failed.

好的,这就是事情,我有一个带tabbarcontroller的应用程序。我在这个tabbarcontroller上有四个选项卡(test1,test3,test4,test5)。如果我已经在第一个选项卡上,当我选择它时,我希望此选项卡从test1更改为test2。目前我设法更改标题,但实际上重新加载视图我必须切换到其他选项卡之一并返回。我现在在这个问题上挣扎了很长一段时间,我似乎无法找到失败的地方。

Here is the code of the controller link with my four tabs: http://pastebin.com/tvJ0PYvR

以下是我的四个选项卡的控制器链接代码:http://pastebin.com/tvJ0PYvR

and here is the code link to my tabbarcontroller : http://pastebin.com/jSw8dPfJ

这是我的tabbarcontroller的代码链接:http://pastebin.com/jSw8dPfJ

Any help would be appreciated, thanks.

任何帮助将不胜感激,谢谢。

1 个解决方案

#1


0  

Ok so here is the answer, almost find it when looking for how to refresh a view http://pastebin.com/w88m5M0Y What one needs to do is deleting the view after detecting the selection (when already on the tab) and recreating the view to display the new one (switching from test1 to test 2 on first tab)

好的,所以这里是答案,几乎在寻找如何刷新视图时找到它http://pastebin.com/w88m5M0Y需要做的是在检测到选择后(当已经在选项卡上时)删除视图并重新创建查看以显示新的(在第一个选项卡上从test1切换到测试2)

Put this in your didSelectItem function :

把它放在你的didSelectItem函数中:

self.viewDidDisappear(false)

self.viewDidDisappear(假)

self.viewWillAppear(true)

self.viewWillAppear(真)

#1


0  

Ok so here is the answer, almost find it when looking for how to refresh a view http://pastebin.com/w88m5M0Y What one needs to do is deleting the view after detecting the selection (when already on the tab) and recreating the view to display the new one (switching from test1 to test 2 on first tab)

好的,所以这里是答案,几乎在寻找如何刷新视图时找到它http://pastebin.com/w88m5M0Y需要做的是在检测到选择后(当已经在选项卡上时)删除视图并重新创建查看以显示新的(在第一个选项卡上从test1切换到测试2)

Put this in your didSelectItem function :

把它放在你的didSelectItem函数中:

self.viewDidDisappear(false)

self.viewDidDisappear(假)

self.viewWillAppear(true)

self.viewWillAppear(真)