如何在也具有导航的 Tabbar 应用程序中调用 viewWillDisappear 方法
我在我的应用程序中创建了 5 个选项卡。在 Tab1 中,我有 UITableView
。在 didSelectRowAtIndexPath
上,我导航到另一个 UIView,其中显示了我的所有 5 个选项卡。我还在那个导航视图中播放歌曲。
现在,当我单击导航中的后退按钮并再次转到原始视图时,我可以调用viewWillDisappear
(如预期和正常情况)。
但是,当我直接单击另一个选项卡时,导航视图中不会调用 viewWillDisappear
。为什么会发生这种情况?
我只是想,当我直接单击另一个选项卡时,Tab1 中的视图将调用viewWillDisappear。但导航视图不会调用该方法。
那么可能的解决方案是什么?请给一些提示...
I have created 5 Tabs in my application. In Tab1 i have UITableView
. On didSelectRowAtIndexPath
i am navigating to another UIView in which I am showing my all 5 Tabs. And I also play song in that navigated view.
Now when I click Back button in navigation and i again go to my original view, i am able to call viewWillDisappear
(as expected and normal situation).
But when I click directly another tab then viewWillDisappear
is not called in the navigated View. Why this Happens??
I have just thought in a way that when I directly clicks the another Tab then the view in Tab1 will call viewWillDisappear. But the navigated view will not call that method.
So what could be possible solutions?? kindly give some hints...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
让 viewWillDisappear 工作
我通过调用viewDidLoad()
,否则, viewWillDisappear 不会被调用。这就是我的内容:
希望这会有所帮助。
I got the viewWillDisappear to work by calling
in viewDidLoad()
Otherwise, viewWillDisappear wasn't getting called. And this is what I have in it:
Hope this helps.
我认为当您在选项卡之间切换时需要捕获该事件。当你从Tab1切换到Tab2时,如你所料,Tab1的
viewWillDisappear
不会被调用。相反,Tab2 的viewWillAppear
将被调用。否则,如果您想在切换选项卡时捕获事件,请检查 此链接。
I think that you need to catch the event when you switch between tabs. When you switch from Tab1 to Tab2, as you expect,
viewWillDisappear
of Tab1 will not be called. Instead, theviewWillAppear
of Tab2 will be called.Else if you want to catch the event when you switch tabs, check this link.
这是因为您已经创建了 tabBarController 并且将其作为 mainView 中的 viewController 推送。
因此整个 TabBarController 被视为一个 viewController。
希望这对您有帮助。
That is because the you have created tabBarController and you are pushing it as a viewController from the mainView.
So whole TabBarController is treated as one viewController.
Hope this helps you.
如果要调用此方法,请创建 nsnotification center 对象 viewWillDisappear
当您想调用此方法时发布此通知。
if you want to call this method create the nsnotification center object viewWillDisappear
and when you want to call this method post this notification.
这就是我让它发挥作用的方法。
That's how I got it to work.