如何在 UITabBarBased 应用程序中每次单击选项卡栏项目时显示不同的视图?
我希望在单击 tabbaritem 1 时显示屏幕 1,如果我更改一些设置,我会进入不同的视图,当我再次单击 tabbaritem 1 时,我想显示屏幕 2。
我有一个基于 UITabbar 的应用程序和 MainWindow。 xib 在视图之前加载了不同的选项卡。
如何以编程方式更改它?
请帮忙
I want screen 1 to be shown when tabbaritem 1 is clicked and if I change some settings, i go to different view, , when I click the tabbaritem 1 again I want to show screen 2.
I have a UITabbar based app and the MainWindow.xib has different tabs loaded before with views.
How do I change it programmatically?
Please help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
只需将要创建的视图的代码放在
viewWillAppear
方法中,而不是viewDidLoad
中。每次返回选项卡 1 时都会调用此函数just put the code for the views to be created in the method
viewWillAppear
instead ofviewDidLoad
. This is being called each time go go back to your tab 1在您的应用程序委托中实现以下方法
,
if(controller.selectedIndex == 3)
3 = 要更改子视图的视图控制器索引。
“replaceSubView”
是视图控制器中要更改子视图的方法。
如有任何困难请告诉我。
干杯。
Implement below method in your App Delegate
Here,
if(controller.selectedIndex == 3)
3 = your viewcontroller index in which you want to change subview.
And "replaceSubView"
is your method in view controller in which you want to change subview.
Let me know in case of any difficulty.
Cheers.
将
MainWindow
或AppDelegate
转换为UITabBarDelegate
,然后使用- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
捕获选项卡选择。当选择您需要的选项卡时,使用
UITabBarItem
的image
属性来设置您喜欢的图像。Turn
MainWindow
orAppDelegate
intoUITabBarDelegate
, than use- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
to caught tab selections. When tab you need is selected, use
image
property ofUITabBarItem
to set image you like.